Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom ASP.NET MVC Route In Nested Folders

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?

like image 460
Kezzer Avatar asked May 12 '09 13:05

Kezzer


2 Answers

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]);
like image 193
Hosam Aly Avatar answered Sep 27 '22 22:09

Hosam Aly


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

like image 44
Derek Ekins Avatar answered Sep 27 '22 22:09

Derek Ekins