I want sub-folders in my MVC application, so the current routes just don't cut it.
I've got a folder structure such as
Views/Accounts/ClientBalances/MyReport.aspx
and I'm wanting a URL such as http://myapp/Accounts/ClientBalances/MyReport
. How do you achieve this with mapping routes? I've had a bash but I'm not very savvy with them. I thought it'd be along the lines of
routes.MapRoute( _
"Accounts/ClientBalances", _
"Accounts/ClientBalances/{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = ""} _
)
I've had no luck though. Any ideas?
Take a look at ASP.NET MVC 2's areas; they look like very similar to what you're trying to achieve. You can watch a quick, 3-minutes video introducing them here.
If you can't (or don't want to) use them, then check this answer about nested view folders. In summary:
You can just return the appropriate view like this (from the action method):
return View("~/Views/controllername/modulename/actionname.ascx", [optional model]);
The location of the view has nothing to do with the route. Your views should be in Views/[ControllerName]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With