views:

786

answers:

3

Hi, by default the ASP.NET MVC engine searches the following folders for View pages:

  • /Views/{Controller_Name}/{Action}.aspx
  • /Views/Shared/{Action}.aspx

However I want to put some of my View pages like this:

  • /Views/{Namespace}/{Controller_Name}/{Action}.aspx

How can I let the engine look for this?

+3  A: 

You have to create a class derived from IViewEngine interface and register this class in Aplication_Start event in Global.asax.cs Check this link text, but there are some differences with 1.0

That's quite a bit, i'm gonna skip that tonight ;-). Thx for the info so far..
Ropstah
Actually, i've read it a bit and I noticed the VirtualPathProviderViewEngine class. That's what I was looking for. Thx!
Ropstah
A: 

I didn`t try this by myself, but it looks quite good.

Arnis L.
+1  A: 

I came up with a different solution that didn't require me to roll my own view engine.

Basically, I wanted to keep MVC as "Convention" driven as possible, but I still wanted to organize all of my "Admin" views under the ~/Views/Admin folder.

Example:

  • ~/Views/Admin/User/
  • ~/Views/Admin/News/
  • ~/Views/Admin/Blog/

My solution was to create a new base class for my specific admin controllers and "force" the path to the view for that controller.

I have a blog post and sample code here: Organize your views in ASP.Net MVC

datacop
I like this, thx!
Ropstah