我的网址如下所示:
customer/login?ReturnUrl=home
在登录视图中,我使用了这种运行良好的代码模式。
@using(Html.BeginForm())
{
...
}
这神奇地生成以下html
<form action="customer/login?ReturnUrl=home" method="post">
但是现在,我需要data-id="something"
在表单中添加一个属性(例如,)。我怎样才能做到这一点?如果我没有任何查询字符串,我知道我可以这样做:
@using(Html.BeginForm(action, controller, FormMethod.Post,
new { data_id="something" }))
但不知道如何添加应该在 html 中的查询字符串:
<form action="customer/login?ReturnUrl=home" method="post" data-id="something">
我考虑过<form>
直接使用,但不知道如何指定可变的查询字符串。而且我不知道如何使用Html.BeginForm
. 任何提示将不胜感激。
解析度:
现在,我使用<form>
了以下提示How to get current url value in View。结果视图看起来像
<form action="@Request.Url.PathAndQuery" data-id="something" method="POST">
但是最好有一个重载的方法BeginForm
。