2012-09-23 62 views
4

後@section腳本不工作,我新手,MVC 4和jQuery Mobile和我想要做的是使用jQuery UI的地圖庫顯示地圖。MVC 4 - jQuery Mobile的 - 導航

這裏就是我:

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" }) 

當我點擊上面的動作鏈接,它將採取用戶的位置,並將顯示在谷歌地圖上的標記。

在地圖上查看頁面我已經在底部

@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. 如何強制頁面重新加載..我已經嘗試做Ajax.Actionlink,或者設置cacheduration在控制器行爲方法爲零,仍然沒有去。

我已經嘗試了所有可用的問題和答案,在這個論壇上,仍然沒有得到它的工作。

任何想法爲什麼會發生這種情況?

回答

1

誓言!我一天的大部分時間都在計算這個......我已經升級了Nuget包,以獲得最新的Web.Optimization和其他DLL,但直到現在仍然是不可行的。

最後,我通過Scott Hanselman's Create a great mobile site來到acorss這篇文章。

在我閱讀文章時,我遇到了這個腳本,並將它放在了我的_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> 
1

如果你想保持Ajax功能,你還可以將@RenderSection(「腳本」,必需:false)在你裏面的數據角色=「頁面「div