asp.net mvc 4 - 表单提交按钮没有响应

时间:2014-02-03 17:18:16

标签: asp.net-mvc submit

我是MVC的新手,并且正在使用VS2013的MVc4。这是我的控制者:

 [HttpPost]
 public ActionResult Create(CreateRequestViewModel viewModel)
 {
    if (ModelState.IsValid)
    {
        return RedirectToAction("Index");
    }             
    return View(viewModel);
}

以下是我的观点:

@model ProMs.Web.ViewModels.CreateRequestViewModel

@{
    ViewBag.Title = "Create";
}

<body>

    <h2>New Request</h2>
    <h3></h3>
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <fieldset>

            <div class="float-left">
                <label for="RequestName">Request</label>
                @Html.EditorFor(model => model.Request.RequestName)
                @Html.ValidationMessageFor(model => model.Request.RequestName)

                @Html.LabelFor(model => model.Request.Requestor)
                @Html.EditorFor(model => model.Request.Requestor)
                @Html.ValidationMessageFor(model => model.Request.Requestor)

                @Html.LabelFor(model => model.Request.Purpose)
                @Html.EditorFor(model => model.Request.Purpose)
                @Html.ValidationMessageFor(model => model.Request.Purpose)
            </div>

            <div class="float-right">
                @Html.LabelFor(model => model.Request.Investigator)
                @Html.EditorFor(model => model.Request.Investigator)
                @Html.ValidationMessageFor(model => model.Request.Investigator)

                @Html.LabelFor(model => model.Request.Department)
                @Html.EditorFor(model => model.Request.Department)
                @Html.ValidationMessageFor(model => model.Request.Stage)

                @Html.LabelFor(model => model.Request.Comment)
                @Html.EditorFor(model => model.Request.Comment)
                @Html.ValidationMessageFor(model => model.Request.Comment)                
            </div>

            @Html.HiddenFor(model => model.Request.RequestID)
            @Html.HiddenFor(model => model.Request.DateCreated)
            @Html.HiddenFor(model => model.Request.CreatedBy)               

        </fieldset>
    }

     <p>
         <input type="submit" value="Submit" />
     </p>

</body>

如果单击“提交”按钮,则没有任何反应。我甚至冷不在线上

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

@Html.BeginForm()会创建一个<form>元素。现在你的提交按钮在这个元素之外,所以把它移到里面。

}

 <p>
     <input type="submit" value="Submit" />
 </p>

应该是

 <p>
     <input type="submit" value="Submit" />
 </p>

} <-- This goes down here