jquery - MVC View returns only json formated data using jqGrid -


using jqgrid in mvc showing json formated text view. new mvc , razor please in detail. find code below.

using system.collections.generic; using system.data; using system.linq; using system.web; using system.web.mvc; using system.data.sqlclient; using system.reflection;   namespace jgridsample.controllers { public class homecontroller : controller {      public actionresult index()     {         return view();     }     [httpget]     public actionresult getjqgriddata(string page, string rows, string sidx, string sord)     {         var jqgriddata = new jqgridobject()         {             data = getloggingdetails(),             page = page,             pagesize = 3,              sortcolumn = sidx,             sortorder = sord         };         return json(jqgriddata, jsonrequestbehavior.allowget);     }      public list<goalogging> getloggingdetails()     {         string connstring = "server=6.15.265.23;database=act2_ol_igp;uid=s_user;pwd=password;pooling=true;connection lifetime=86400;min pool size=50;max pool size=2000";         sqlconnection conn = new sqlconnection(connstring);         sqlcommand cmd = new sqlcommand();         cmd.commandtype = commandtype.storedprocedure;         cmd.commandtext = "get_sampledetails";         cmd.connection = conn;         conn.open();         datatable datatable = new datatable();         sqldataadapter da = new sqldataadapter(cmd);         da.fill(datatable);         conn.close();         da.dispose();          list<goalogging> items = new list<goalogging>();         foreach (datarow row in datatable.rows)         {             items.add(new goalogging { crt_dt = convert.todatetime(row["crt_dt"]),                                          process_flg = row["process_flg"].tostring(),                                         status_code = row["status_code"].tostring(),                                         status_message = row["status_message"].tostring(),                                         serv_trans_id = row["serv_trans_id"].tostring()                                         });         }         return items;     }      public class jqgridobject     {         public string page { get; set; }         public int pagesize { get; set; }         public string sortcolumn { get; set; }         public string sortorder { get; set; }         public list<goalogging> data { get; set; }     }      public class goalogging     {         public string serv_trans_id { get; set; }         public string status_code { get; set; }         public string status_message { get; set; }         public string process_flg { get; set; }         public datetime crt_dt { get; set; }     }      } } 

view code:

@{    layout = null; } <!doctype html>  <html> <head> <meta charset="utf-8" /> <title></title> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <meta name="viewport" content="width=device-width" /> <link href="../../content/site.css" rel="stylesheet" type="text/css" /> <link href="../../content/jquery.jqgrid/ui.jqgrid.css" rel="stylesheet" type="text/css" /> <link href="../../content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" /> <script src="~/scripts/jquery.jqgrid.min.js"></script> <script src="~/scripts/jquery.jqgrid.js"></script> <script src="~/scripts/jquery-ui-1.10.0.min.js"></script> <script src="~/scripts/jquery-ui-1.10.0.js"></script> <script src="~/scripts/jquery-1.9.1.min.js"></script> <script src="~/scripts/jquery-1.9.1.js"></script> <script src="~/scripts/jquery-1.9.1.intellisense.js"></script> <script type="text/javascript">     $(document).ready(function () {         $("#mygrid").jqgrid({             url: '/home/getjqgriddata',             datatype: 'json',             mytype: 'get',             colnames: ['serv_trans_id', 'status_code', 'status_message', 'process_flg', 'crt_dt'],             colmodel: [             { name: 'serv_trans_id', index: 'serv_trans_id' },             { name: 'status_code', index: 'status_code' },             { name: 'status_message', index: 'status_message' },             { name: 'process_flg', index: 'process_flg' },             { name: 'crt_dt', index: 'crt_dt' }             ],             pager: $('#mypager'),             rownum: 5,             width: 600,             viewrecords: true,             caption: 'grid view'         });     });  </script> </head> <body> <table id="mygrid"></table>  <div id="mypager"></div> </body> </html> 

and url have used http://localhost:52326/home/getjqgriddata please find result getting enter image description here

this happens because calling jsonresult rather actionresult in controller.

reference example


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -