【发布时间】:2022-01-26 03:35:13
【问题描述】:
我正在尝试使用Html.ActionLink 生成带有查询字符串参数的 URL,例如:
Controller/Action?id=5
但我得到的是:
Controller/Action/5
使用:
@Html.ActionLink((string)ViewBag.Back, "Action", "Controller", new{id = Model.Id }, new { })
如何将 id 参数作为 "?id=" 而不是在 "/" 之后传递 谢谢
【问题讨论】:
-
该控制器操作的方法签名是什么,它的路由定义是什么?听起来该路线已经包含
id作为参数。这在某种程度上不起作用吗? -
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
-
public ActionResult Details(Nullable
id) -
这就解释了。
id已经是路由的一部分,并且 action 方法有一个id参数。这不适合你吗?为什么要将其更改为查询字符串参数?为此,您需要更改路由或更改操作方法参数名称。 -
我不知道为什么它不能那样工作.. 感谢人的解释,我试着让它在两个方面都工作
标签: c# html asp.net-mvc razor frontend