Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my Extension Controller
C#
public ActionResult Index()
      {
          return View();
      }

      [HttpGet]
      public JsonResult LoadData()
      {
          MvcBasicSiteEntities1 _db = new MvcBasicSiteEntities1();
          {
              var  users = new List<User>();
              var userList = _db.Users.ToList();
              var data = userList.ToArray();

              var result = new
              {
                 rows=(from item in data
                       select new
                       {
                           ID = item.ID,
                           Username = item.Username,
                           Password = item.Password,
                           Role = item.Role,
                           Email = item.Email

                       }).ToArray()
              };
              return Json(result, JsonRequestBehavior.AllowGet);
          }
      }


This is my index view
C#
<head>
    <link href="~/Cont/dd.css" rel="stylesheet" />
    <link href="~/Cont/Site.css" rel="stylesheet" />
    <link href="~/Cont/ui.jqgrid.css" rel="stylesheet" />
</head>

<table id="_extensionLogGrid" cellpadding="0" cellspacing="0">
</table>
<div id="_extensionLogPager" style="text-align: center;">
</div>


<script src="~/Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
        debugger;
        $("_extensionLogGrid").jqGrid({
            onload: location.href = '@Url.Action("LoadData", "Extension")',
            datatype: 'json',
            colNames: ['Id', 'UserName', 'Password', 'Email', 'Role', 'AddressId'],
            colModel: [
                        { name: '_id', index: '_id', width: 300 },
                        { name: 'UserName', index: 'Username', width: 300 },
                        { name: 'Password', index: 'Password', width: 150 },
                        { name: 'Email', index: 'Email', width: 150 },
                        { name: 'Role', index: 'Role', width: 120 },
                        { name: 'AddressId', index: 'AddressId', width: 70 }
            ],

            pager: jQuery('#_extensionLogPager'),
            sortname: 'ID',
            rowNum: 10,
            rowList: [10, 20, 50, 100],
            sortorder: "desc",
            width: 790,
            height: 464,
            caption: 'Users',
            viewrecords: true,
            mtype: 'GET',
            loadonce: true
        });
    })


</script>


I added jqGrid script file in Bundle.config file.

After run it displayed like this

{"rows":[{"ID":1,"Username":"Administrator","Password":"tm77dac","Role":1,"Email":"admin@yahoo.com"},{"ID":3,"Username":"Ana","Password":"ana","Role":2,"Email":"ana@yahoo.com"},{"ID":4,"Username":"Ion","Password":"ion","Role":2,"Email":"ion@yahoo.com"},{"ID":5,"Username":"Vasile","Password":"vasile","Role":2,"Email":"vasile@basicsite.ro"},{"ID":6,"Username":"vanmala","Password":"vanmala","Role":1,"Email":"vanmala@basicsite.com"}]}


what is wrong with this.
Posted
Updated 29-Jun-14 23:30pm
v2

1.I see that you are using part of my code from my next article: MVC Basic Site: Step 4 – jqGrid Integration in MVC 4.0 using AJAX, JSON, jQuery, LINQ, and Serialization[^] but you did not fallow the steps indicated in my article.

2.Your problem is that you forgot to include the jqGrid library (and it is doing the rendering of the JSON data), so you are missing the next js file: jquery.jqGrid.min.js
 
Share this answer
 
Comments
Vanmala 11-Jul-14 2:04am    
I include it in my bundle.config file.
I was done small project based on this article.It works fine
Change in jqGrid

C#
url:'@Url.Content("~/Extension/LoadData")',  
 
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