gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:33:30 25 4
gpt4 key购买 nike

我正在使用 RouteValueDictionary 将 RouteValues 传递给 ActionLink:

如果我编码:

<%: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 } })%>

关于c# - RouteValueDictionary 和 htmlAttributes 之间是否存在冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11685580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com