I am using a RouteValueDictionary to pass RouteValues to a ActionLink:
If I code:
<%:Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, null)%>
The link result is 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) })%>
The link result is:
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's the problem? The only difference is that in the last i am using htmlAttributes
You are using the wrong overload of the ActionLink helper. There's no overload that takes routeValues
as a RouteValueDictionary
and htmlAttributes
as an anonymous object. So if Model.FirstRouteValues
is a RouteValueDictionary
then the last argument must also be a RouteValueDictionary
or a simple IDictionary<string,object>
and not an anonymous object. Just like that:
<%= 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 } })%>
There's no overload that matches your parameters, you should either use object
for route and html or RouteValueDictinary
and IDictionary<string,object>
.
Like so:
Html.ActionLink(SharedResources.Shared_Pagination_First, Model.ActionToExecute, Model.ControllerToExecute, Model.FirstRouteValues, new Dictionary<string.object> { { "title", somevalue } })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With