2017-04-05 62 views
0

我有一個MainView「About.cshtml」它有一個腳本標籤和一個局部視圖。javascript的加載順序

<script> 
    $(function() {} 
</script> 
<div> 
    @Html.Partial("~/Views/Maps/_MapDetailsList.cshtml", Model.saVM) 
</div> 

內部 「_MapDetailList.cshtml」 部分觀點我正在引用另一個腳本ge.js

@Scripts.Render("~/Scripts/ge.js") 
<table id="MapDetails"> 
     ..... 
    <tr><th> 
    <script>setGrowthArray(1, 1);</script> 
    </th></tr> 
</table> 

ge.js

var dictionaryGrowth = new Array(); 

function setGrowthArray(colIndex, mapDetailId) { 
//making a sparse array 
dictionaryGrowth[colIndex] = mapDetailId; 
} 

現在我想給這個dictionaryGrowth陣列到頁面/表格加載後的服務器端

so i的確在About.cshtml腳本以下,但因此未工作..

<script> 
    $(function() { 
    $("#MapDetails").load(function() { alert("everything seems fine");}); 
    } 
</script> 

也請告訴我會在我的情況下,腳本和DOM加載順序。

UPDATE 大概當前序列是

  1. 腳本上About.cshtml執行
  2. ge.js執行局部視圖內
  3. 的document.ready燒製
  4. javascript函數(setGrowthArray)從內部DOM被稱爲
  5. 現在我想打電話給我的控制器? 如果我寫的window.onload = ...裏面ge.js這是從來沒有發射

回答

0

您也可以替換使用$.post()爲​​,合格setGrowthArray(1, 1)的結果發佈到服務器數據

<script> 
$.post("/path/to/server", {growth:setGrowthArray(1, 1)}, function(data) { 
    console.log(data); // response from server 
    $("#MapDetails").html(data); 
}) 
</script> 
+0

做我還需要在控制器中標記服務器端動作爲[HttpPost] – Samra

+0

在服務器檢查'POST'請求,其中鍵是''growth'' – guest271314

+0

請參閱我的更新..現在它說Uncaught ReferenceError:dictionaryGrowth沒有在兩個$ .post和$(document).load – Samra