How to assign controller name and action name dynamically in asp.net mvc
-
Dynamically to what? when? Give an exampleDan– Dan2009-04-10 11:08:37 +00:00Commented Apr 10, 2009 at 11:08
-
Im writing my own route handler ...in that i want to specify action name ...depending upon my requirementsvecsuresh– vecsuresh2009-04-10 11:13:27 +00:00Commented Apr 10, 2009 at 11:13
Add a comment
|
1 Answer
On HttpApplication.Application_Start your can add dynamically any routes (Controller and Action anme) to RouteTable.Routes, this you can use any information available in this event or ever populate routes from config file or database.
For example
new Route( "Admin/{actionName}/{slug}/", CreateRouteHandler())
{
Defaults = new RouteValueDictionary(defaults),
Url = new RouteValueDictionary(dataTokens)
}
You couldn't change actions in RouteHandler, you could process current HttpRequest in your different ways, for example.