为什么Ajax.ActionLink更新整个页面,而不是仅仅UpdateTarget [英] Why is Ajax.ActionLink updating entire page instead of just UpdateTarget

查看:362
本文介绍了为什么Ajax.ActionLink更新整个页面,而不是仅仅UpdateTarget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该只是更换UpdateTarget,但它不,它取代了整个页面,我不明白为什么。正确的局部视图被返回,但不是替换目标ID,它替换整个页面。

This should replace just the UpdateTarget, but it does not, it replaces the entire page and I don't see why. The correct partial view is being returned, but instead of replacing the target id, it is replacing the entire page.

<div id="magHeader">
        <p>this is a test.</p>
        @Ajax.ActionLink("Edit", "GetEditor", "Home", new AjaxOptions(){ UpdateTargetId = "magHeader", InsertionMode = InsertionMode.Replace})
</div>

在运行时,链接如下:

At runtime, the link looks like this:

<a href="/Home/GetEditor" data-ajax-update="#magHeader" data-ajax-mode="replace" data-ajax="true">Edit</a>

有什么,我做错了什么?在过去,没有问题,成功地做到了这一点。

Is there something that I am doing wrong? Have done this successfully in the past with no issues.

修改
此问题的根本原因是,在2012 VS,你只需要添加一个引用到JQueryVal包,使这项工作。然而,在2013年,BundleConfig.cs已更改,以便在JQueryVal束不再包含JQuery.Unobtrusive。所以,简单的解决方法是增加它放回包:

Edit The underlying reason for this issue is that in VS 2012, you only needed to add a reference to the JQueryVal bundle to make this work. However, in 2013, the BundleConfig.cs was changed so that the JQueryVal bundle no longer includes JQuery.Unobtrusive. So the simple fix is to add it back into the bundle:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*"));

然后按预期都将正常工作。

Then all will work as expected.

推荐答案

检查是否加载 @ Scripts.Render(〜/包/ jqueryval)到您的页面的某个地方或没有。这可能是因为不显眼的JavaScript文件是没有得到加载。勾选此影片

Check if you are loading @Scripts.Render("~/bundles/jqueryval") into your page somewhere or not. It is probably because unobtrusive javascript file is not getting loaded. Check this video

编辑:结果
请检查您的package安装在packages.config文件。


Please check if you there packages installed in your packages.config file.

<package id="Microsoft.jQuery.Unobtrusive.Ajax" version="3.1.1" targetFramework="net451" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net451" />

这篇关于为什么Ajax.ActionLink更新整个页面,而不是仅仅UpdateTarget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆