我的網址使用Html.BeginForm看起來是這樣的:與查詢字符串
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
此重載方法。
你要在哪裏添加屬性,窗體或窗體中的東西? – msarchet
您是否希望添加其他表單值或動態設置查詢字符串? – Tejs
@msarchet和Tejs我想要表單元素上的屬性。 –