开发者

jquerygrid with asp.net mvc razor view engine

开发者 https://www.devze.com 2023-02-14 16:29 出处:网络
I\'m trying to follow this example on Phil haak\'s blog using the razor viewengine. Except my view renders the json as text instead of displaying the grid.

I'm trying to follow this example on Phil haak's blog using the razor viewengine.

Except my view renders the json as text instead of displaying the grid.

Here is the code for my view :

@{
    ViewBag.Title = "Home Page";
}

<h2>@ViewBag.Message</h2>

<script src="../../Scripts/jquery.jqGrid.min.js" type="text/javascript"></script>

 <script type="text/javascript">
     jQuery(document).ready(function () {
         jQuery("#list").jqGrid({
  开发者_运维知识库           url: '/Home/DynamicGridData/',
             datatype: 'json',
             mtype: 'GET',
             colNames: ['Id', 'Votes', 'Title'],
             colModel: [
          { name: 'Id', index: 'Id', width: 40, align: 'left' },
          { name: 'Votes', index: 'Votes', width: 40, align: 'left' },
          { name: 'Title', index: 'Title', width: 400, align: 'left'}],
             pager: jQuery('#pager'),
             rowNum: 10,
             rowList: [5, 10, 20, 50],
             sortname: 'Id',
             sortorder: "desc",
             viewrecords: true,
             imgpath: '/scripts/themes/coffee/images',
             caption: 'My first grid'
         });
     }); 
    </script>  

    <table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>

The rendered page looks like this :

{"total":3,"page":1,"records":22,"rows":[{"i":37,"cell":["37","1","What does AcceptVerbs do?"]},{"i":36,"cell":["36","1","Can I change the default model binder?"]},{"i":35,"cell":["35","1","How do I do custom paging?"]},{"i":34,"cell":["34","1","Writing a custom ControllerFactory"]},{"i":33,"cell":["33","65","How do I defend against CSRF attacks?"]},{"i":32,"cell":["32","2","If there was a random question generator, would you use it?"]},{"i":30,"cell":["30","51","Is there a random question generator?"]},{"i":29,"cell":["29","2","How many questions are in this table?"]},{"i":28,"cell":["28","7","How do I use the SelectList?"]},{"i":27,"cell":["27","50","How do I use jQuery grid with MVC"]}]}
0

精彩评论

暂无评论...
验证码 换一张
取 消