我正在使用RouteValueDictionary将RouteValues传递给ActionLink:
如果I代码:

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

链接结果正常:
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

最佳答案

您正在使用ActionLink帮助程序的错误重载。没有将routeValues作为RouteValueDictionaryhtmlAttributes作为匿名对象的重载。因此,如果Model.FirstRouteValuesRouteValueDictionary则最后一个参数也必须是RouteValueDictionary或简单的IDictionary<string,object>而不是匿名对象。就像这样:

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


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

08-26 22:40