【问题标题】:ASP.NET MVC4 Ajax.ActionLink replaces entire pageASP.NET MVC4 Ajax.ActionLink 替换整个页面
【发布时间】:2013-04-28 06:13:25
【问题描述】:

在我看来,我有:

 @section Header {
     @Scripts.Render("~/bundles/jqueryval")
 }

<div>
    <div>@Ajax.ActionLink("Test", "CurrentTime", new AjaxOptions { UpdateTargetId = "some_div", InsertionMode = InsertionMode.InsertAfter })</div>
</div>

<div id="some_div">

</div>

在结果页面的标题中,我看到引用了这些脚本:

<script src="/Scripts/jquery-1.6.4.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

链接看起来像这样:

<div><a data-ajax="true" data-ajax-mode="after" data-ajax-update="#some_div" href="/Tournament/CurrentTime">Test</a></div>

在控制器中:

public string CurrentTime()
{
    return DateTime.Now.ToLongTimeString();
}

在我的 web.config 中(在应用程序的根目录中):

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

我的问题是:每当我点击链接时,结果(当前时间)总是替换整个页面 - 它没有插入到 some_div 之后/之后/之前。 谢谢

【问题讨论】:

  • 在 chrome 或 firefox 中查看错误控制台。可能你的脚本没有加载
  • @Garath:谢谢! FireBug 发现:TypeError: $(...).on is not a function $(document).on("click", "a[data-ajax=true]", function (evt) { 但我没有编辑脚本(至少我不知道)。请问我该如何解决?它在 jquery.unobtrusive-ajax 文件中。谢谢

标签: ajax asp.net-mvc asp.net-mvc-4 unobtrusive-javascript unobtrusive-ajax


【解决方案1】:

根据您的评论,答案很简单,您必须升级 jQuery。 on 方法适用于 jquery 1.7。我建议使用 jquery 1.7.2,因为 mvc 脚本有时会遇到更高版本的问题

【讨论】:

猜你喜欢
  • 2014-07-25
  • 2017-05-27
  • 2015-07-10
  • 2019-06-19
  • 2019-04-29
  • 1970-01-01
  • 1970-01-01
  • 2011-12-08
  • 1970-01-01
相关资源
最近更新 更多