4

我是 mvc 4 和 jquery mobile 的新手,我想做的是使用 jquery-ui-map 库显示地图。

这是我所拥有的:

1)在布局页面上,我在“正文结束”标签之前的底部有以下代码

@Scripts.Render("~/bundles/jquery","~/bundles/jqueryui")
@Scripts.Render("~/bundles/jquerymobile")
@RenderSection("scripts", required: false)

2)在索引视图上,我有以下操作链接

@Html.ActionLink("Display Map","Map", "Home", null, 
        new { data_role = "button", data_theme = "b", data_mini = "true" })

当我单击上述操作链接时,它将获取用户位置并在谷歌地图上显示标记。

在 MAP 视图页面上,我在底部有以下代码

@section scripts{

     <script type="text/javascript" src="http://maps.google.com/maps/apis?sensor=false">
     </script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/map/demo.js")"></script>
    @Scripts.Render("~/Scripts/map/jquery.ui.map.min.js")
    @Scripts.Render("~/Scripts/map/jquery.ui.map.overlays.min.js")
    @Scripts.Render("~/Scripts/map/jquery.ui.map.extensions.js")
    $(function () {
            //code to display the map
        });
 } 

这是我遇到的问题....当我单击操作链接时,它将显示地图视图但不显示地图。

如果我刷新页面(f5 或单击浏览器刷新图标),它将调用$function()并显示地图。

  1. @section我在标签上做错了吗?
  2. 如何强制页面重新加载它.. 我试过 do Ajax.Actionlink,或者cacheduration在 Controller Action 方法中设置为零,仍然不行。

我已经尝试了该论坛中所有可用的问题和答案,但仍然无法正常工作。

知道为什么会这样吗?

4

2 回答 2

1

发誓!!我花了大部分时间才弄清楚这个……我已经升级了 nuget 包,以获得最新的 Web.Optimization 和其他 dll,但直到现在它仍然不行。

最后,我看到了Scott Hanselman 的 Create a great mobile site 的这篇文章。

在阅读这篇文章时,我偶然发现了这个脚本并将其放在我的 _Layout 页面中。现在我的网站按预期工作....

<script type="text/javascript">
 $(document).bind("mobileinit", function () {
     // jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
     // when navigating from a mobile to a non-mobile page), especially when going    back, hence disabling it.
     $.mobile.ajaxEnabled = false;
  });
    </script>
于 2012-09-24T01:20:57.573 回答
1

如果你想保留 ajax 功能,你也可以移动 @RenderSection("scripts", required: false) 在你里面 data-role="page" div

于 2012-10-01T13:33:32.760 回答