Mike Smith
Mike Smith

Reputation: 642

MVC Routes & Subfolders

I'm trying to figure out a way to customize a Route that will allow me to use a subfolder within a particular View folder.

I have a Controller (FinanceAdmin) and a View folder (\FinanceAdmin) which contains a number of Views. Within that view folder, I have a lot of stand alone chart Views (Chart1, Chart2...Chart50, etc...) which I include as Partials on various View pages. To clean things up in my file/organizational structure, I would like to set things up like this:

filetree

I know I can use Areas to separate different parts of my application but that's not really what I'm looking for. I want to be able to create a custom Route so that, in my controller, I can simply return:

return View(chartdata);

instead of

return View("~/Views/FinanceAdmin/Chart/_Chart1.cshtml",chartdata);

Is that possible with a generic route (so I don't have to create one for each file)? I'd rather not write a custom view engine just for this unique circumstance.

Upvotes: 2

Views: 2664

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039508

I am afraid that this is not possible with a route. The routing engine finishes his responsibility at the time he finds (or doesn't find) a controller action to be executed given some request url.

Resolving views is purely the responsibility of the view engine. So if the conventions built into the view engine you are using do not meet your specific requirements, customizing this view engine is the right way to go.

Upvotes: 2

Related Questions