表单提交按钮从不提交表单

时间:2014-09-02 18:10:14

标签: asp.net asp.net-mvc-4

我正在使用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()?

1 个答案:

答案 0 :(得分:0)

问题是由于MVC 4 服务器端客户端验证错误导致表单提交被阻止。如果不使用@Html.ValidationSummary,我很难在当时看到这些错误。