Tag: ajax.beginform

MVC5 Ajax.BeginForm刷新整个页面

为什么表单post没有通过ajax发生,而是重新加载到新页面? 我的.js包括: 我的剃刀观点: @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”}) @Html.ValidationMessageFor(x=>x.Email) @Html.PasswordFor(x => x.Password, new {placeholder = “Password”}) @Html.ValidationMessageFor(x => x.Password) } 我的控制器代码: [HttpPost] public ActionResult Login(LoginInputModel login) { return PartialView(“Widgets/Popups/_LoginInput”, login); } 我忘了什么吗?

Ajax.BeginForm(),OnSuccess – 获取事件目标

我无法获得在Ajax.BeginForm()触发OnSuccess()方法的元素的目标。 所以这是代码片段: @using (Ajax.BeginForm(“InsertModel”, “Home”, new AjaxOptions { HttpMethod = “POST”, OnSuccess = “doWork(this,’SomeCustomText’)” })) { } function doWork(e,customText) { alert(customText); //It shows ‘SomeCustomText’, so its good. alert(e); //[Object] object alert(e.prop(“tagName”)); //Object # has no method ‘prop’ alert(e.attr(“tagName”)); //Object # has no method ‘attr’ alert(jQuery(e).html()); //undefined alert(jQuery(e).prop(“tagName”)); //undefined alert(e.target); //undefined alert(jQuery(e).target); //undefined } 问题: 如何获得目标?! […]

MVC4 Ajax.BeginForm没有替换UpdateTargetId

关于Ajax.BeginForm的问题,有很多关于使用返回局部视图正确更新目标元素的问题: mvc4 ajax更新同一页面 ASP.NET MVC 4 – Ajax.BeginForm和html5 MVC 4(razor) – 控制器返回部分视图但整个页面正在更新 MVC 4 Ajax没有更新页面中的PartialView 但是,所有这些都可以通过手动写出jQuery ajax或包含丢失的javascript文件来解决。 @using (Ajax.BeginForm(“PostcardDetails”, new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = “details” })) { @{Html.RenderAction(“PostcardSearchResults”, Model);} } 相关控制器代码: [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)] public ActionResult PostcardSearchResults(PostcardSearchFilter filter) { PostcardSearchResults model = new PostcardSearchResults(filter); return PartialView(“_PostcardSearchResults”, model); } 在我的布局中,我引用了这些jQuery文件。 此外,我已经validation页面正在输出正确的路径,并且它找到了正确的文件。 我试过切换unobtrusive-ajax.min.js和validate.min.js的顺序,但没有成功。 此外,在我的网站的根web.config和我的View文件夹中的web.config,我已经包括: […]