Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
this is my controller

C#
public JsonResult gridview() 
        {
  

  var jsonData = new {
    total = 1, //todo: calculate
    page = 1,
    records = db.TestModels.Count(),
    rows = (
      from question in db.TestModels.AsEnumerable()
      //where question.Emailid=="sudarshan@gmail.com"
      select new  {
        id = question.Dataid,
        cell = new string[3] { 
          question.Dataid.ToString(), question.Name, question.Emailid 
        } 
      }).ToArray()
  };
  return Json(jsonData, JsonRequestBehavior.AllowGet);
}
    }
}

this is my view

C#
<link rel="stylesheet" type="text/css" href="~/jqgrid/css/ui.jqgrid.css" 
  title="coffee" media="screen" />
<script src="~/Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="~/jqgrid/src/jquery.jqGrid.js" type="text/javascript"></script>
<script src="~/jqgrid/src/jqModal.js" type="text/javascript"></script>
<script src="~/jqgrid/src/jqDnR.js" type="text/javascript"></script>

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



<script type="text/javascript">
    jQuery(document).ready(function(){ 
      jQuery("#list").jqGrid({
          url: '/Test/gridview/',
        datatype: "json",
       
        colNames: ['Dataid', 'Name', 'Emailid'],
        colModel :[
         { name: 'Dataid', index: 'Dataid', width: 40, align: 'left' },
          { name: 'Name', index: 'Name', width: 40, align: 'left' },
          { name: 'Emailid', index: 'Emailid', width: 200, align: 'left' }],
        pager: jQuery('#pager'),
        rowNum:10,
        
        sortname: 'Dataid',
        sortorder: "desc",
        viewrecords: true,
       
          
        caption: "My  grid"
      }); 
    }); 
</script>
and this the output

C#
{"total":1,"page":1,"records":11,"rows":[{"id":18,"cell":["18","aditya","cast@gmail.com"]},{"id":19,"cell":["19","anil","anil@gmail.com"]},{"id":20,"cell":["20","cast","cast@gmail.com"]},{"id":21,"cell":["21","revision","revision@gmail.com"]},{"id":22,"cell":["22","sham","adityakashyap@gmail.com"]},{"id":23,"cell":["23","anil","aditya@gmail.com"]},{"id":24,"cell":["24","sham",null]},{"id":25,"cell":["25","anil","adityakashyap@gmail.com"]},{"id":26,"cell":["26","sudarshan","sudarshan@gmail.com"]},{"id":27,"cell":["27","board","board@gmail.com"]},{"id":28,"cell":["28","seen ","seen@gmail.com"]}]}

can anybody help me out
Posted
Updated 30-Apr-14 0:48am
v2
Comments
Sampath Lokuge 30-Apr-14 7:39am    
Check whether are there any js errors on your js file by using chrome dev tool ?
Member 10785068 30-Apr-14 7:41am    
am new to this mvc environment could u explain ..
Sampath Lokuge 30-Apr-14 7:44am    
Please read this : https://developers.google.com/chrome-developer-tools/docs/javascript-debugging

1 solution

If your beginner to MVC then pls refere my blog.
I have also created videos explaining it.
A simple demo on MVC Entity framework and JQGrid.

I guess it will be helpfull for you.

http://dotnetsourcedileep.blogspot.in/2014/06/test.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900