Is there a conflict between RouteValueDictionary and htmlAttributes?

I use RouteValueDictionary to pass RouteValues ​​to ActionLink:

If I code:

<%:Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, null)%> 

Link Result: Ok:

 SearchArticles?refSearch=2&exact=False&manufacturerId=5&modelId=3485&engineId=-1&vehicleTypeId=5313&familyId=100032&page=0 

But if I code:

 <%: Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new { @title = string.Format(SharedResources.Shared_Pagination_LinkTitle, 0) })%> 

Link Result:

 SearchArticles?Count=10&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D 

What is the problem? The only difference is that in the last I use htmlAttributes

+4
source share
2 answers

You are using the wrong overload of the ActionLink helper. There is no overload that accepts routeValues as RouteValueDictionary and htmlAttributes as an anonymous object. Therefore, if Model.FirstRouteValues is RouteValueDictionary , then the last argument should also be RouteValueDictionary or a simple IDictionary<string,object> , and not an anonymous object. Similar:

 <%= Html.ActionLink( SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new RouteValueDictionary( new { title = string.Format(SharedResources.Shared_Pagination_LinkTitle, 0) } ) ) %> 

or

 <%=Html.ActionLink( SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new Dictionary<string, object> { { "title", somevalue } })%> 
+7
source

There is no overload that matches your parameters, you must either use object for the route and html, or RouteValueDictinary and IDictionary<string,object> .

Same:

 Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new Dictionary<string.object> { { "title", somevalue } }) 
+1
source

All Articles