2

I'm a newbie to ASP.Net MVC 4.0 and I'm trying to use Trirand's JQGrid populating data from database. I'm getting the above error when I try to bind the data to JQGrid.

The error is at the below line

 return gridModel.MarketPriceAnalysisGrid.DataBind(oMarketPriceAnalysisModel.AsQueryable<MarketPriceAnalysisModel>());

Code below :

 // This method is called when the grid requests data
    public JsonResult SearchGridDataRequested()
    {
        // Get both the grid Model and the data Model          
        var gridModel = new MarketPriceAnalysisJQGridModel();


        // customize the default Orders grid model with our custom settings
        SetUpMarketPriceAnalysisGrid(gridModel.MarketPriceAnalysisGrid);


        var oMarketPriceAnalysisModel = MarketPriceAnalysisRepository.GetListOfSAPSPTComponents();                           

        // return the result of the DataBind method, passing the datasource as a parameter
        // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
         return gridModel.MarketPriceAnalysisGrid.DataBind(oMarketPriceAnalysisModel.AsQueryable<MarketPriceAnalysisModel>());
    }

The method GetListofSAPSPTComponents returns an IEnumerable

 IEnumerable<MarketPriceAnalysisModel> GetListOfSAPSPTComponents();

I just figured that the error source is Trirand.Web.MVC and the stack trace says

`at Trirand.Web.Mvc.Util.PrepareJsonResponse(JsonResponse response, JQGrid grid,   DataTable dt)
  at Trirand.Web.Mvc.Util.ConvertToJson(JsonResponse response, JQGrid grid, DataTable   dt)
  at Trirand.Web.Mvc.JQGrid.FilterDataSource(Object dataSource, NameValueCollection queryString, IQueryable& iqueryable)
  at Trirand.Web.Mvc.JQGrid.GetJsonResponse()
  at Trirand.Web.Mvc.JQGrid.DataBind()
  at Trirand.Web.Mvc.JQGrid.DataBind(Object dataSource)
  at MedPackMVC.Controllers.MarketPriceAnalysisController.SearchGridDataRequested() in      c:\Work\04_Dev\MedPackMVCApplication\MedPackMVC\Controllers\MarketPriceAnalysisController.cs:line 95

`

Not sure what could be the possible cause for this? Thanks

siv
  • 71
  • 1
  • 4
  • 12
  • possible duplicate of [What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) – Forty-Two Mar 19 '13 at 16:34
  • Eventually, `MarketPriceAnalysisRepository.GetListOfSAPSPTComponents()` returns null. Have you checked it? – Dima Mar 19 '13 at 16:51
  • @Dima - No it returns the data from the Database. – siv Mar 19 '13 at 16:53
  • 1
    I figured out the issue. The Datafield names for the JQGrid werent properly mapped to the database column names. – siv Mar 19 '13 at 20:06
  • Thanks @siv, I faced the same issue and your above comment helped me to identify one of the column alias I used was not matching with JQGridColumn.DataField. Please post this as the answer because it might help some one else. – user007 Oct 09 '14 at 17:28

1 Answers1

1

Also this error can be appeared when your MarketPriceAnalysisModel have fields instead properties which are assigned to jqGrid.

Anton Norko
  • 1,926
  • 1
  • 13
  • 18