Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.
Given the following action methods in a single controller:
[RequireRouteParameters] public ActionResult Index()
and [RequireRouteParameters] public ActionResult Index([FromRoute] int someParam)
A link the the second, more specific action cannot be generated using Html.ActionLink. Even if you provide the “someParam” parameter as a route value, it will generate a link to the parameterless Index method, with the someParam value appended to the querystring.
I have attached a sample project to demonstrate the issue. Just start it up and you will see an explanation on the default action/view. There are two links there, and both point to the same parameterless Index method no matter how you adjust the call to Html.ActionLink. The problem also exists with other url-generating methods (like Url.Action).
(Sorry for all the issues lately; just testing this as thoroughly as I can.)
- Status
- Closed
- ReasonClosed
- Fixed
- AffectedComponent
- Web.Mvc
- PlannedForRelease
- v0.9.0
- ClosedDate
- LastUpdatedDate
- FileAttachments
Don’t be sorry, thank you for all the testing you’ve done, it would have taken me months to find these issues myself.
This issue exists only for actions in the root controller, because I’m putting the “{action}” route at the top. For other controllers the routes with most parameters come first, precisely to avoid the url generation issue.
I’m not sure what your patch does, but my solution would be to order the routes for the root controller the same ways as it’s done for the rest.
About MVC copying the current route values, this would only be an issue if the current request has the someParam value. I other cases you shouldn’t need the empty string.
Thanks again, we are getting close to 1.0 :-)