0

I am using JQGrid with my mvc code.

My controller is

//
        // GET: /Leave/

        public ActionResult CompOff()
        {
            var compoffs = db.RegisterCompOffs.Where(l => l.Employee.Id == this.EmployeeId).ToList();
            return Json(compoffs, JsonRequestBehavior.AllowGet);

        }</code>

compoffs is not null here.. and my view is

@model AGS.Hrms.Models.RegisterCompOff

@{
    ViewBag.Title = "CompOff";
}

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


<script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>
 <script type="text/javascript">
     $(document).ready(function () {
         $('#jqgProducts').jqGrid({
             //url from wich data should be requested
             url: this.href,
             //type of data
             datatype: 'json',
             //url access method type
             mtype: 'GET',
             //columns names
             colNames: ['CompOffDate', 'IsApproved', 'Description', 'ExpiryDate','IsUtilized'],
             //columns model
             colModel: [
                            { name: 'CompOffDate', index: 'CompOffDate', align: 'left' },
                            { name: 'IsApproved', index: 'IsApproved', align: 'left' },
                            { name: 'Description', index: 'Description', align: 'left' },
                            { name: 'ExpiryDate', index: 'ExpiryDate', align: 'left' }
                            { name: 'IsUtilized', index: 'IsUtilized', align: 'left' }

                          ],
             //pager for grid
             pager: $('#jqgpProducts'),
             //number of rows per page
             rowNum: 10,
             //initial sorting column
             sortname: 'CompOffDate',
             //initial sorting direction
             sortorder: 'asc',
             //we want to display total records count
             viewrecords: true,
             //grid height
             height: '100%'
         });
     });
    </script></code>

While requesting for this view I'm getting this 500 Internal server error in console window of Firebug. Can some one tell me what im doing wrong here?

2
  • 1
    any exception messages , stack trace .. etc ? Commented Jun 26, 2012 at 8:19
  • NetworkError: 500 Internal Server Error - localhost:10659/Leave/CompOff", thats it...its in console window of firebug, wont give anything more than it, my application is taking me localhost:10659/Leave/CompOff with html of shared file in plain text Commented Jun 26, 2012 at 8:25

1 Answer 1

1

Two possibilities that come to mind:

  1. The following line var compoffs = db.RegisterCompOffs.Where(l => l.Employee.Id == this.EmployeeId).ToList(); throws an exception. To see if this is the case simply put a breakpoint inside the controller action. To fix this error you will have to analyze the exception and what is causing it.
  2. The compoffs object returned by the query contains circular references and cannot be JSON serialized. To see if this is the case explore the Response of the AJAX request in the FireBug console and look for the exact error message contained in the response sent from the server. It will be something along the lines of: Cannot serialize blablah because it contains circular references. To fix this error you will have to use view models and pass to the view only what it actually needs instead of passing your entire domain object graph.

Another thing that is wrong with your code is the follownig line:

url: this.href,

There's no this.href inside a document.ready handler so I guess the AJAX request doesn't even reach the controller. Make sure you have specified the correct url to the controller action that is supposed to return JSON:

url: '@Url.Action("CompOff")',
Sign up to request clarification or add additional context in comments.

6 Comments

Did you fix the url => url: '@Url.Action("CompOff")', instead of url: this.href,?
no luck..and with your second solution, i'm using everything what i'm passing in compoffs
Is the controller action invoked? What happens? Are you getting an error? What do you see in the Response in FireBug?
action invoked when it goes to return ..it generates this exception
A circular reference was detected while serializing an object of type 'AGS.Hrms.Models.Competency'.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.