2016-06-20 37 views
1

enter image description here當我必須使用@section腳本?

我目前的結構有一個頁眉,正文和頁腳的佈局。在body內部使用ajax加載一個視圖來調用一個動作控制器返回一個Json並繪製一個樹形視圖。當用戶點擊樹形視圖時,頁腳應該加載詳細信息。但沒有工作,我的猜測是因爲腳本部分沒有正確渲染。

現在腳本在佈局中沒有捆綁或任何東西,因爲我使用Jquery和樹來加載Json數據,所以在主體上工作正常。

但在部分視圖中出現錯誤。我可以編寫一個@section scripts區域並從部分視圖中複製佈局中的所有腳本,但爲什麼我應該複製代碼?

enter image description here

最糟糕的是隻給我的問題在生產環境......在我devolpment環境工程確定。

enter image description here

所以問題:

  • 爲什麼主視圖可以看到腳本的佈局,但局部視圖犯規定義?

  • 爲什麼我的開發環境工作正常,但生產不?

  • 我該怎麼做才能解決這個問題?

編輯:更多測試。

這是一個測試視圖,在體內渲染。但我需要包含腳本部分,否則對話框不顯示,即使佈局也有腳本。

@{ 
    ViewBag.Title = "TreeDetails";  
} 
<html> 
<head> 
    <title>@ViewBag.Title</title> 
</head> 
<body> 
    <h2>TEST PAGE</h2> 

    <script> 

     // Your code goes here. 
     $(document).ready(function() { 
      console.log("before dialog"); 
      $("#dialog").dialog(); 
      console.log("after dialog"); 
     }) 
    </script> 

    <div id="dialog" title="Basic dialog"> 
     <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p> 
    </div> 

</body> 
</html> 

@section scripts { 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
} 
+0

你有你'樹狀腳本也加載在佈局內?是用'@ scripts'部分完成的,還是隻用普通的'

相關問題