2013-08-20 268 views
0

我_Layout.cshtml這樣jqGrid不渲染mvc3剃鬚刀?

<head> 
     <meta charset="utf-8" /> 
     <title>@ViewBag.Title - E-Reader Statistics</title> 
     <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
     <meta name="viewport" content="width=device-width" /> 
     @Styles.Render("~/Content/css") 
     @Scripts.Render("~/bundles/modernizr") 
     @* @Scripts.Render("~/bundles/jquery")*@ 
     <link href="~/jqGrid/css/ui.jqgrid.css" rel="stylesheet" /> 
     <script src="~/jqGrid/js/i18n/grid.locale-en.js"></script> 
     <script src="~/jqGrid/js/jquery-1.9.0.min.js"></script> 
     <script src="~/jqGrid/js/jquery.jqGrid.min.js"></script> 
     <script src="~/jqGrid/js/jquery.jqGrid.src.js"></script> 


    </head> 
在Index.chtml

@model List<LSStatisticalReport.ViewModels.GSViewModel> 

@{ 
    ViewBag.Title = "Index"; 
} 

@*<h2>General Statistics</h2>*@ 

<script type="text/javascript"> 
    // var jq = $.noConflict(); 
    $(document).ready(function() { 
     var genStatGrid = $('#list'); 

     genStatGrid.jqGrid({ 
      caption: "General Statistics", 
      url: '/Statistics/GetRecords/', 
      datatype: "json", 
      contentType: "application/json; charset-utf-8", 
      mtype: 'POST', 
      colNames: ['Student', 'Teacher', 'Date'], 
      colModel: [ 
          { name: 'studentDesignation' }, 
          { name: 'teacherDesignation' }, 
          { name: 'dateLength' }, 
       ], 
      rowNum: 5 
     }); 
    }); 
</script> 

但是,當我運行我得到的控制檯錯誤的項目:

「遺漏的類型錯誤:對象[對象對象]沒有方法'jqGrid'「

+0

'jquery-1.9.0.min.js'應該寫在'grid.locale-en.js'之前 –

回答

0

這種類型的錯誤說:請定義j在相關的init腳本之前的qgrid庫。儘管您已經在head標籤中定義了相關庫,但我之前已經看到過此錯誤。所以我解決了這個問題,通過從head標籤中移除它的庫並將它放在腳本前的視圖中並正常工作。

我認爲這是由於頁面的部分加載而發生的。所以在索引視圖中使用它:

@model List<LSStatisticalReport.ViewModels.GSViewModel> 

@{ 
    ViewBag.Title = "Index"; 
} 

@*<h2>General Statistics</h2>*@ 
//added 
<script src="~/jqGrid/js/jquery.jqGrid.min.js"></script> 
<script src="~/jqGrid/js/jquery.jqGrid.src.js"></script> 
//end added 
<script type="text/javascript"> 
    // var jq = $.noConflict(); 
    $(document).ready(function() { 
     var genStatGrid = $('#list'); 

     genStatGrid.jqGrid({ 
      caption: "General Statistics", 
      url: '/Statistics/GetRecords/', 
      datatype: "json", 
      contentType: "application/json; charset-utf-8", 
      mtype: 'POST', 
      colNames: ['Student', 'Teacher', 'Date'], 
      colModel: [ 
          { name: 'studentDesignation' }, 
          { name: 'teacherDesignation' }, 
          { name: 'dateLength' }, 
       ], 
      rowNum: 5 
     }); 
    }); 
</script>