【发布时间】:2017-12-28 11:52:02
【问题描述】:
我正在使用 html.beingform 来生成要发布的网址
@using (Html.BeginForm("action", "ctrl", new { id = 5, name = "a" }))
生成的网址是
<form action="/ctrl/action/5?name=a" method="post">
但它应该生成为
<form action="/ctrl/action?name=a&id=5" method="post">
我使用的语法有什么问题??
编辑
我根据 cmets 尝试了以下语法
@using (Html.BeginForm("action", "ctrl", new { [id] = 5, name = "a" }))
上面给了我错误
@using (Html.BeginForm("action", "ctrl", new { @id = 5, name = "a" }))
上面还是把它加到了url
【问题讨论】:
-
我会先尝试
[id] = 5,因为id对ASP.NET MVC 有特殊意义。 -
默认路由已经定义了一个可选的
id参数,所以它被添加到路由而不是查询字符串中。 -
@AndyG 没用,检查 cmets
-
@Crowcoder 那么如何绕过这个限制呢?
-
在您的 RegisterRoutes 方法中,您应该调用 MapRoute 来添加它。你可以在那里删除它。
标签: c# asp.net-mvc html.beginform