Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
I am trying to implement JqGrid in MVC3 using helpers, but all the time i get a javascript error -"JavaScript runtime error: Object doesn't support property or method 'jqGrid'".I also add reference of MVCJqgrid in my project.
Here is my code for Jqgrid in view :-

VB
@(Html.Grid("AgentGrid")
    .SetCaption("Agents")

    .AddColumn(new MvcJqGrid.Column("AgentId").SetLabel("Agent SSN"))
        .AddColumn(new MvcJqGrid.Column("Name"))
        .AddColumn(new MvcJqGrid.Column("Country"))
        .AddColumn(new MvcJqGrid.Column("City"))
        .AddColumn(new MvcJqGrid.Column("Title"))
        .SetUrl(Url.Action("List", "Home"))
    .SetAutoWidth(true)
    .SetRowNum(10)
    .SetViewRecords(true)
    .SetPager("pager")
    )



and here is my code of action in controller:-

public ActionResult List(GridSettings gridSettings)
       {
           DataContext db = new DataContext();

           string Name = string.Empty;
           string Country = string.Empty;
           string City = string.Empty;
           string Title = string.Empty;

           if (gridSettings.IsSearch)
           {
               Name = gridSettings.Where.rules.Any(r => r.field == "Name") ?
                      gridSettings.Where.rules.FirstOrDefault(r => r.field == "Name").data : string.Empty;
               Country = gridSettings.Where.rules.Any(r => r.field == "Country") ?
               gridSettings.Where.rules.FirstOrDefault(r => r.field == "Country").data : string.Empty;
               City = gridSettings.Where.rules.Any(r => r.field == "City") ?
              gridSettings.Where.rules.FirstOrDefault(r => r.field == "City").data : string.Empty;
               Title = gridSettings.Where.rules.Any(r => r.field == "Title") ?
              gridSettings.Where.rules.FirstOrDefault(r => r.field == "Title").data : string.Empty;

           }

           var Agents = db.Agent.ToList();
           int totalAgents = Agents.Count;
           var jsonData = new
           {
               total = totalAgents / gridSettings.PageSize + 1,
               page = gridSettings.PageIndex,
               records = totalAgents,
               rows = (
                       from c in Agents
                       select new
                       {
                           id = c.AgentId,
                           cell = new[]
                   { c.AgentId.ToString(),
                       string.Format("{0} {1}", c.Name, c.Country),
                       c.City,
                       c.Title
                   }
                       }).ToArray()
           };

           return Json(jsonData, JsonRequestBehavior.AllowGet);
       }


Please suggest me for resolve the issue !!
Thanks in advance!!
Posted
Updated 21-Aug-13 19:42pm
v2
Comments
Jameel VM 22-Aug-13 2:22am    
did you put the jqgrid script ?
Antariksh Verma 22-Aug-13 2:25am    
I have added the reference of MvcJqgrid dll which provides mvc html helpers of grid!!
Antariksh Verma 22-Aug-13 2:26am    
I have add JQGrid dll reference which provide us MVCJqgrid helpers!!

1 solution

You should the jQGrid Scripts and jQuery script for running the application.Please go through this link for more help. Please the download the application mentioned this application and look at the head section of the layout page
jqGrid MVC Html Helper[^]
hope this helps
 
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