Saturday, 5 December 2009

?length=5 at the end of an ActionLink

I tried to add an action link to a view which would link to an action on a different controller but the links did not generate correctly and ended with ?length=5.

The following ActionLink was used on a view used by a job controller (JobController):

<%= Html.ActionLink("Edit", "Edit", "Query", new{ id = item.Id }) %>

This should have generated a link to the Edit action on the Query controller. However the links generated as follows:

http://<server here>/Job/Edit?Length=5

In other words they were still generated as if they were on the Job controller (I was using the standard {controller}/{action}/{id} type route).

The fix is to add null at the end of the call to ActionRoute:

<%= Html.ActionLink("Edit", "Edit", "Query", new{ id = item.Id }, null) %>

There are a stack of overrides of the ActionLink method and this forced ASP.Net MVC to use the right one.


Post a Comment

By all means leave a comment. I may not be able to get back to you as quickly as I'd like but I'll do my very best.