2010-11-16 53 views
1

我正在寻求标准化使用MVC在服务器端处理ajax #anchors。与asp.net mvc2使用jquery移动时的哈希导航问题

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

例如:

1)/用户/简档#用户/照片应被视为/用户/照片

2)/主/索引#用户/简档/ 33应被视为/用户/简档/ 33

MVC中最好的技术是什么?那是什么?

回答

0

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

+0

你能告诉我,告诉我怎么样?因为我对此比较陌生? – hasan 2010-11-16 11:29:12

+0

这很大程度上取决于您的场景。请求是如何执行的?你在使用表格,动作链接...... – 2010-11-16 11:57:35

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