gpt4 book ai didi

asp.net-mvc - ActionLink 显示 URL 中的参数而不是查询字符串?

转载 作者:行者123 更新时间:2023-12-02 04:56:13 26 4
gpt4 key购买 nike

我定义了这条路线:

routes.MapRoute(
"Details", // Route name
"{home}/{details}/{id}/{name}", // URL with parameters
new
{
controller = "Home",
action = "Details",
id = UrlParameter.Optional,
name = UrlParameter.Optional
} // Parameter defaults
);

操作链接:

 @Html.ActionLink("Show Details", "Details", "MyController", new { id = 1, name ="a" })

actionlink 结果为 /Home/Details/1?name=a 我在 /Home/List/1/a

最佳答案

你的路由定义应该是这样的:

routes.MapRoute(
"Details", // Route name
"{controller}/{action}/{id}/{name}", // URL with parameters
new
{
controller = "Home",
action = "Details",
id = UrlParameter.Optional,
name = UrlParameter.Optional
} // Parameter defaults
);

您还应该使用 proper overload :

@Html.ActionLink(
"Show Details", // linkText
"Details", // action
"MyController", // controller
new { id = 1, name = "a" }, // routeValues
null // htmlAttributes
)

注意末尾的null

关于asp.net-mvc - ActionLink 显示 URL 中的参数而不是查询字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7499320/

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