RouteValueDictionary和htmlAttributes之间是否存在冲突?

时间:2012-07-27 10:02:02

标签: c# asp.net-mvc html-helper actionlink routevalues

我使用RouteValueDictionary将RouteValues传递给ActionLink:

如果我编码:

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

链接结果为Ok:

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

但如果我编码:

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

链接结果为:

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

有什么问题?唯一的区别是在最后我使用的是htmlAttributes

1 个答案:

答案 0 :(得分:1)

没有与您的参数匹配的重载,您应该使用object路由 html或RouteValueDictinaryIDictionary<string,object>

像这样:

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