Handling trivial and complex Actions with Routes

ericchestnut

New Member
I would like to design our Controllers and Actions like this:There is one Action for every Controller called "StaticPage(string page)" (thought about creating a BaseController to derive from it but for now, we will talk only about "Suite" as Controller).
This Action returns Views, that are containing mostly HTML code and no Model.So instead of creating 20 Actions for 20 trivial Views, I would like one Action to manage and differ them by a parameter. But on the same Controller, I would like them to have Actions that return Views with Model and do more complex and database related stuff. At first, I thought about following routes (Note: In this Scenario, there exists an area "Product"):\[code\] context.MapRoute( "Product_default", "Product/{controller}/{action}", new { action = "index"} ); context.MapRoute( "StaticPage_Route", "Product/{controller}/{page}", new { action = "StaticPage", page = UrlParameter.Optional );\[/code\]So lets say we got the View TechnicalSpecification.cshtml and TrivialPage.cshtml and when I call
\[quote\] /Product/Suite/TechnicalSpecification\[/quote\]it should search and find the Action "TechnicalSpecification", but when I try\[quote\] /Product/Suite/TrivialPage\[/quote\]it should also first search the Action "TrivialPage". But then, when it doesnt find it, it should treat it as an Parameter called page (like in the Routes I've mentioned above).But I don't really know, how to manage this right.Is there a way without setting an custom ActionFilter Attribute, that checks something in OnActionExecuted(...) and then does something to call the "StaticPage"-Action?
 
Back
Top