Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please give me the solution for Binding jqgrid with entity framework via controller using json and also need jqgrid template

Thank you...
Posted
Comments
Sunasara Imdadhusen 23-Apr-14 0:43am    
Have tried to search on google?
Member 10629036 23-Apr-14 0:48am    
I am tried already in google but i did'nt get proper solution please give me the solution for this

Hi,

You can refer below code in order to resolve the issue that you faced.
This is the template for jq Grid which is written in view

VB
@(Html.Grid("GridName")
 .SetRequestType(MvcJqGrid.Enums.RequestType.Post)
 .SetJsonReader(new MvcJqGrid.DataReaders.JsonReader { Id = "WId" })
 .SetCaption("View Report")

      .AddColumn(new Column("Name").SetWidth(100).SetLabel(" Name").SetSearchType(MvcJqGrid.Enums.Searchtype.Text))
.AddColumn(new Column("Description").SetWidth(100).SetLabel("Description").SetSearchType(MvcJqGrid.Enums.Searchtype.Text))
.AddColumn(new Column("Status").SetWidth(100).SetLabel("Status").SetSearchType(MvcJqGrid.Enums.Searchtype.Text))
     .AddColumn(new Column("Resource").SetWidth(100).SetLabel("Resource").SetSearchType(MvcJqGrid.Enums.Searchtype.Text))

    .SetUrl(Url.Action("ViewName", "ControllerName"))
    .SetAutoWidth(true)
    .SetRowNum(10)
    .SetSortName("WId")
    .SetViewRecords(true)
    .SetPager("pager")
    .SetLoadOnce(true)//for client side sorting and paging enabled
           
  .SetSearchToolbar(true)
  .SetAutoWidth(true)
  .SetSearchClearButton(true)
  .SetSearchToolbar(true)
  .SetSearchOnEnter(false)
  .SetScroll(false)
  .SetPgButtons(true)
  .SetSearchClearButton(true)
  .SetSearchToggleButton(true)
  )


You can use it in controller like below:-

C#
public JsonResult ViewName(GridSettings gridSettings)
       {
           int totalRecords;
           SREntities db = new SREntities();
           totalRecords = db.VW_GetData.Count();
           var jsonData = new
           {
               total = totalRecords / gridSettings.PageSize + 1,
               page = gridSettings.PageIndex,
               records = totalRecords,
               rows = db.VW_GetData.ToList()

           };

           return Json(jsonData, JsonRequestBehavior.AllowGet);
       }


You have to add reference of a DLL for JQGrid "MvcJqGrid.dll " and also add jquery file in _Layout.cshtml

XML
<script src="@Url.Content("~/Scripts/i18n/grid.locale-en.js")" type="text/javascript"></script>
   <script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>


Refer this link for furthur help:
mvcjqgrid.skaele.it/

Thats all done !!
 
Share this answer
 
v2
Comments
Member 10629036 23-Apr-14 4:56am    
Thank you....
well in controller write your logic to get the required data and then you can use json.Net library to convert your data to json serialize object and pass it to your view.


this is just a direction that i am providing, you can do some more research on json.net framework. you can install json.net from nuget package in the visual studio.


hope this will helpful.
 
Share this answer
 
v2
Comments
Member 10629036 23-Apr-14 4:55am    
Thank you....
Hi..

You can refer my article.

http://www.codeproject.com/Articles/801895/Asp-Net-MVC-Entity-Framework-and-JQGrid-Demo-wit

this will be good for beginner with a simple demo application using MVC, Entity framework and jqgrid.
 
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