我正在使用MVC 4表單:表單提交按鈕從不提交表單
查看:
@model etc.Models.FormViewModel
@using (Html.BeginForm("NewForm", "Form", FormMethod.Post))
{
// html helpers here ...
<div class="row">
<div class="form-group col-lg-2 col-lg-offset-5">
<button type="submit" class="btn" value="Submit">Submit</button>
</div>
</div>
}
控制器:
[HttpPost]
public ActionResult NewForm()
{
FormViewModel newForm = new FormViewModel(); //this will never get hit
return View();
}
點擊提交不做任何事情。它只是讓頁面向上滾動一點,並專注於特定的輸入字段。當我填充該字段和其他字段,然後再次單擊提交時,無論我在控制器操作的頂部是否包含[HttpPost]
,都不會調用NewForm()。我該如何做到這一點,以便當你點擊提交按鈕時,NewForm()被調用?我如何真正將表單數據傳遞給NewForm()?
確認您在瀏覽器的調試網絡監視器或使用Fiddler等工具發出POST請求。 – Jasen 2014-09-02 18:14:22
我剛纔嘗試了這個,但它並沒有觸發任何POST請求。 – alex 2014-09-02 18:20:28
你有任何javascript攔截提交請求?如果您使用任何數據驗證,請嘗試關閉任何數據驗證。 – Jasen 2014-09-02 18:22:08