MVC5 Ajax.BeginForm刷新整个页面 [英] MVC5 Ajax.BeginForm refresh whole page
本文介绍了MVC5 Ajax.BeginForm刷新整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么通过AJAX的形式后没有发生,而是被重新加载到新页
Why is the form post not happening via ajax but instead is reloading to the new page?
我的.js文件包括:
<script src="/App/JavaScript/Libraries/jquery-1.11.1-min.js"></script>
<script src="/App/JavaScript/Libraries/jquery.validate.js"></script>
<script src="/App/JavaScript/Libraries/jquery.validate.unobtrusive.js"></script>
我的Razor视图:
My razor view:
<div id="login-partial-update">
@using (Ajax.BeginForm("Login",null, new AjaxOptions
{
UpdateTargetId = "login-partial-update",
HttpMethod = "POST"
}, new { id = "js-form-login" }))
{
@Html.TextBoxFor(x => x.Email, new {placeholder = "Email address"})
<div class="errormessage">
@Html.ValidationMessageFor(x=>x.Email)
</div>
@Html.PasswordFor(x => x.Password, new {placeholder = "Password"})
<div class="errormessage">
@Html.ValidationMessageFor(x => x.Password)
</div>
}
</div>
我的控制器代码:
My controller code:
[HttpPost]
public ActionResult Login(LoginInputModel login)
{
return PartialView("Widgets/Popups/_LoginInput", login);
}
我是不是忘了什么东西?
Am I forgetting something?
推荐答案
您必须包括 jquery.unobtrusive-ajax.js
文件在您的视图,使 Ajax.BeginForm
工作
You have to include jquery.unobtrusive-ajax.js
file in your view to make Ajax.BeginForm
to work.
这篇关于MVC5 Ajax.BeginForm刷新整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文