none
Ajax.BeginForm 提交后产生两个表单 RRS feed

  • 问题

  • Model 类

    C# code
    public class Department { public string Name { get; set; } public string Description { get; set; } }
    Controller 类
    C# code

    public class DepartmentController : Controller { [HttpGet] public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create(TestEntity.Department department) { ViewBag.MyMessage = "Error Message1"; return View(); } }

    View 

    View
    @model TestEntity.Department @{ ViewBag.Title = "Create Department"; Layout = null; } <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> <h2>Create Department</h2> @using (Ajax.BeginForm("Create", "Department", new AjaxOptions { UpdateTargetId = "divForm", HttpMethod="POST" })) { <fieldset> <legend>Create Department</legend> @Html.LabelFor(m => m.Name) @Html.TextBoxFor(m => m.Name, new { id="txtName", style="background-color:#CFDFFC"}) @ViewBag.MyMessage <br /> @Html.LabelFor(m => m.Description) @Html.TextBoxFor(m => m.Description) <br /> <input type="submit" id="btnSubmit" value="Create" /> </fieldset> } <div id="divForm"></div>

    进行异步提交之后,在 <div id="divForm"></div> 内部显示了正确的信息,但是不合理的是,原来的表单还在。如此一来,异步提交之后,页面上显示两个创建部门的表单了


    2012年11月2日 9:43

答案

全部回复