I have an area which is registered as:
public override void RegisterArea(AreaRegistrationContext context) {
context.MapRoute("CPanel_default",
"CPanel/{controller}/{action}/{id}/{*urlData}",
new { id = UrlParameter.Optional, urlData = UrlParameter.Optional });
}
This route is intended to full a number of urls:
- /cpanel/home/index
- /cpanel/entity/edit/20
- /cpanel/entity/edit/20/abitrary-url-data
Haack’s route debugger has shown me that the route is functioning in this capacity. However, my code for generating action links has recently broken and I haven’t been able to find out the cause of the break.
Action links are being generated with the following code:
public static MvcHtmlString CpanelLink(this HtmlHelper @this, string linkText,
string actionName, string controllerName, string areaName = "CPanel") {
return @this.ActionLink(linkText,
actionName, new { controller = controllerName, area = areaName });
}
Which, as far as I can tell, should account for all the required fields in the area route. Debugging shows that CpanelLink is returning <a href="">...</a>, a link to nothing.
Edit
Additional troubleshooting has reveled that the route parameter {*urlData} is killing Html.CpanelLink. Reducing the route to “CPanel/{controller}/{id}” clears the issue, but breaks urls which depend on the urlData parameter.
The problem is you can’t pass the controller name in as a route parameter.
You need to use the following ActionLink() method signature
Note the last parameter value is ‘null’ which represents the html attributes.
UPDATE:
The other problem is to do with consecutive optional parameters, as described in Phil Haack’s blog post
So you need to do the workaround as such;