6

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?

2 Answers 2

3

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]);
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.