MVC4 Ajax.BeginForm不更换UpdateTargetId [英] MVC4 Ajax.BeginForm not replacing UpdateTargetId
问题描述
有那么多的话题对SO有关问题与Ajax.BeginForm没有正确更新与回报局部视图的目标元素:
mvc4 AJAX更新同一页面
ASP.NET MVC 4 - Ajax.BeginForm和HTML5 < BR>
<一href="http://stackoverflow.com/questions/13374035/mvc-4-razor-controller-is-returning-a-partialview-but-entire-page-is-being-u">MVC 4(剃刀) - 控制器返回一个partialview,但整个页面正在更新
<一href="http://stackoverflow.com/questions/13626225/mvc-4-ajax-is-not-updating-the-partialview-within-the-page">MVC 4阿贾克斯没有在页面
内更新PartialView
然而,所有的这些都通过手动写出了jQuery AJAX,或包括一个丢失的JavaScript文件回答
There are so many topics on SO about issues with the Ajax.BeginForm not correctly updating the target element with the return partial view:
mvc4 ajax updating same page
ASP.NET MVC 4 - Ajax.BeginForm and html5
MVC 4 (razor) - Controller is returning a partialview but entire page is being updated
MVC 4 Ajax is not updating the PartialView within the page
However, all of these are answered by either manually writing out the jQuery ajax, or including a missing javascript file.
@using (Ajax.BeginForm("PostcardDetails", new AjaxOptions()
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "details"
}))
{
<div id="PostcardSearchResults">
@{Html.RenderAction("PostcardSearchResults", Model);}
</div>
}
<div id="details">
</div>
相关控制器code:
Relevant controller code:
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
public ActionResult PostcardSearchResults(PostcardSearchFilter filter)
{
PostcardSearchResults model = new PostcardSearchResults(filter);
return PartialView("_PostcardSearchResults", model);
}
在我的布局,我引用这些jQuery的文件。此外,我已经验证了页面输出正确的路径,并找到正确的文件。我试着切换不显眼-ajax.min.js顺序
和 validate.min.js
,没有成功。
In my layout, I am referencing these jQuery files. Additionally, I've verified that the page is outputting the proper path, and that it finds the correct files. I've tried switching the ordering of unobtrusive-ajax.min.js
and validate.min.js
, to no success.
<script type="text/javascript" src="@Url.Content("~/Scripts/globalize.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.9.1.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.10.0.custom.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
此外,在我的网站的根web.config,在我看来,文件夹中的web.config文件,我已经包括:
Additionally, in my website's root web.config, and the web.config in my View folder, I have included:
<add key="webpages:Version" value="2.0.0.0"/>
<add key="PreserveLoginUrl" value="true"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
我在为别的地方看的损失。有被抛出任何JavaScript错误,控制器被正确地打,返回PartialViewResult。在HTML表单元素填充所有正确的数据 -
属性
推荐答案
有一个与jquery.unobtrusive-ajax.min和jQuery 1.9的一个问题因为jQuery 1.9不支持直播()方法,任何的more 。所以,你应该使用JQuery的迁移插件,并引用JQuery的迁移JS。
There is a problem with jquery.unobtrusive-ajax.min and JQuery 1.9 because JQuery 1.9 doesn't support the live() method any more. So you should use the JQuery migrate plug-in, and reference the JQuery migrate js.
这篇关于MVC4 Ajax.BeginForm不更换UpdateTargetId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!