ASP.NET MVC custom route in subfolders

I want subfolders in my MVC application, so current routes just don't cut.

I have a folder structure like

Views/Accounts/ClientBalances/MyReport.aspx 

and I want a url like http://myapp/Accounts/ClientBalances/MyReport . How do you achieve this with matching routes? I had bash, but I do not really understand them. I thought it would be along the line

  routes.MapRoute( _ "Accounts/ClientBalances", _ "Accounts/ClientBalances/{controller}/{action}/{id}", _ New With {.controller = "Home", .action = "Index", .id = ""} _ ) 

I was not lucky. Any ideas?

+6
asp.net-mvc-routing
source share
2 answers

Take a look at the ASP.NET MVC 2 area ; they look very similar to what you are trying to achieve. You can watch a quick, 3-minute video that is presented here .

If you cannot (or do not want) to use them, then this answer is about subfolders of viewing. In short:

You can simply return an appropriate view similar to this (from the action method):

 return View("~/Views/controllername/modulename/actionname.ascx", [optional model]); 
+3
source share

The location of the view has nothing to do with the route. Your views should be in views / [controller_name]

+1
source share

All Articles