在使用jQuery Mobile的使用asp.net MVC2哈希导航问题 [英] Hash navigation problem while using jquery mobile with asp.net mvc2

查看:151
本文介绍了在使用jQuery Mobile的使用asp.net MVC2哈希导航问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待在服务器端,以规范AJAX #anchors的处理,使用MVC。

I am looking to standardize the processing of ajax #anchors at the server side, using MVC.

在一个控制器动作被调用我想与阿贾克斯锚每个请求转换成没有Ajax锚的要求,使控制器code不知道有请求主播:

Before a controller action is invoked I want to convert every request with ajax anchors into a request without ajax anchors, so that the controller code does not know there were anchors in the request:

例如:

1)/用户/ profile文件#用户/照片应该被视为/用户/照片

1) /user/profile#user/photos should be treated as /user/photos

2)/主/指​​数#用户/型材/ 33应被视为/用户/型材/ 33

2) /main/index#user/profile/33 should be treated as /user/profile/33

什么是MVC中最好的技术来实现这一目标?

What is the best technique in MVC to accomplish that?

推荐答案

我也有同样的问题斗争,我在看的Visual Studio 11开发preVIEW模板code后解决了这个问题。我说在我的_layout.cshtml以下code,请注意,我们必须加载jquery.mobile * .js文件的 下面的脚本标记之后:

I too struggle with same issue and I solved this problem after looking at Visual Studio 11 Developer Preview template code. I added following code in my _layout.cshtml, please note we must load jquery.mobile*.js file after following script tag:

 <script type="text/javascript">
          $(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. http://jquerymobile.com/demos/1.0a3/#docs/api/globalconfig.html
              @{
                  if (ViewBag.JqueryMobileAjaxEnabled != null && ViewBag.JqueryMobileAjaxEnabled == true)
                  {
                    @: $.mobile.ajaxEnabled = true;
                  }
                  else
                  {
                    @: $.mobile.ajaxEnabled = false;
                  }
              }
          });
        </script>
     **<script src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>**

这篇关于在使用jQuery Mobile的使用asp.net MVC2哈希导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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