How does HtmlHelper.ActionLink(htmlhelper,string linktext,string action) figures out correct route?
If i have this=>
HtmlHelper.ActionLink("Edit","Edit")
Mvc automatically finds out correct route.
i.e. – if controller was Product, it will render anchor with href product/edit.
So – how to figure out controller name when i got htmlHelper + action name combo?
If your HtmlHelper looks something like:
Then from your helper, access:
The RouteData object contains all the values that were processed by ASP.NET Routing for the current request. This will include the parameter names and values from the route, such as “{controller}/{action}/{id}”. Many of the built-in ASP.NET MVC helpers grab “ambient” data from there so that the developer doesn’t have to type them in for every helper they use.
You can also download the full source code to ASP.NET MVC from here: