asp.net-mvc - ajax 链接处理不当

标签 asp.net-mvc jquery-mobile

我有一个带有 jquery-mobile 应用程序的 asp.net mvc 4。

在一个页面(url:/StatementBatch)上,我有一个批处理列表,它们只是指向批处理详细信息页面(url:/StetementBatch/Details/4)的链接。

<li>
    <a href="/StatementBatch/Details/4">
        <h3>January 2012</h3>

        <div style="float: right; width: 30%;"><strong>Issued  : </strong>1/10/2012 12:00:00 AM</div>
        <div style="float: right; width: 30%;">Completed</div>

        <p class="ui-li-aside"><strong>1277</strong></p>
    </a>


</li>

奇怪的是,一旦单击链接并呈现详细信息页面,浏览器的当前 URL 现在为 http://localhost:49457/StatementBatch#/StatementBatch/Details/4

我需要在应用中进行哪些更改才能修复此行为?

我的猜测是它是某种与ajax加载相关的问题,但是我共享的_Layout.cshtml文件包含$.mobile.ajaxEnabled = false;,我预计这会杀死所有ajax加载,但是我显然误解了这一点。

谢谢!

最佳答案

我怀疑这可能就是答案

jQuery Mobile ajaxEnabled doesn't work?

将测试看看是否可以使其工作

mobileinit 绑定(bind)移至 jquery 之后、jquery-mobile 之前即可实现此目的。这似乎是 MVC4(新)移动 Web 应用程序模板中的一个错误,该模板只是将所有脚本捆绑在一起

失败了......

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script>

<script>
    $(document).bind("mobileinit", function() {
        // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
        // when navigating from a mobile to a non-mobile page, or when clicking "back"
        // after a form post), hence disabling it.
        $.mobile.ajaxEnabled = false;
    });
</script>

但是这有效......

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />

<script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>

<script>
    $(document).bind("mobileinit", function() {
        // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
        // when navigating from a mobile to a non-mobile page, or when clicking "back"
        // after a form post), hence disabling it.
        $.mobile.ajaxEnabled = false;
    });
</script>

<script src="../../Scripts/jquery.mobile-1.1.0.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
<script src="../../Scripts/modernizr-2.5.3.js" type="text/javascript"></script>

谢谢...

关于asp.net-mvc - ajax 链接处理不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10433897/

相关文章:

c# - ASP.NET MVC 4,C# : how to Download File

jquery - jQuery/iframe 文件上传解决方案的问题

jquery - jquery mobile 的导航栏中的选择未正确发生

javascript - 禁用 JavaScript 时的 Css 回退

ios - iOS PhoneGap jQuery 移动应用程序中的可见滚动条

asp.net-mvc - 如何在 Razor 助手中使用 UrlHelper?

c# - ASP.NET MVC ViewModel 属性为空

javascript - Vue.js 组件点击事件找不到方法

jquery - SQLite数据库+Jquery Mobile

javascript - 使用 addEventlistener 在移动设备上启用/禁用主体滚动