ada*_*iko 14 asp.net ajax asp.net-mvc asp.net-mvc-4
我正在尝试使用MVC 4中的Ajax.BeginForm帮助器方法将表单从同步转换为异步.
在我看来,我有:
@{
ViewBag.Title = "Users > Edit";
var options = new AjaxOptions()
{
Url = Url.Action("Edit", "User"),
LoadingElementId = "saving",
LoadingElementDuration = 2000,
Confirm = "Are you sure you want to save this User?"
};
}
<div id="saving" style="display:none; color:Red; font-weight: bold">
<p>Saving...</p>
</div>
@using (Ajax.BeginForm(options))
{
@Html.ValidationSummary(true)
<fieldset>
.... FIELDS ...
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
单击提交按钮时,正在执行完整的回发.我的动作方法如下所示:
[HttpPost]
public ActionResult Edit(User user)
{
if (ModelState.IsValid)
{
_repository.Save(user);
TempData["message"] = String.Format("{0} has been saved.", user.Username);
}
return View(user);
}
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?MVC 4当前版本是否有一些问题?
在我的Web.Config中,我确实将ClientValidationEnabled和UnobtrusiveJavaScriptEnabled设置为true.
我也在_Layout.cshtml中指定了这些:
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 28
有什么我想念的吗?
也许你错过了不引人注目的ajax脚本:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)