使用带有asp.net mvc2的jquery mobile时出现哈希导航问题

时间:2010-11-16 09:46:08

标签: asp.net-mvc jquery

我希望使用MVC标准化服务器端的ajax #anchors处理。

在调用控制器操作之前,我想将带有ajax锚点的每个请求转换为没有ajax锚点的请求,以便控制器代码不知道请求中有锚点:

例如:

1)/ user / profile#user / photos应被视为/ user / photos

2)/ main / index #user / profile / 33应被视为/ user / profile / 33

MVC中最好的技术是什么?

2 个答案:

答案 0 :(得分:0)

这必须在客户端完成,可能使用jquery,因为#符号后面的所有内容都不会发送到服务器。

答案 1 :(得分:0)

我也在努力解决同样的问题,在查看Visual Studio 11 Developer Preview模板代码后我解决了这个问题。我在_layout.cshtml中添加了以下代码,请注意我们必须在脚本标记之后之后加载jquery.mobile * .js文件

 <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>**