2

我是 ASP.Net MVC 4.0 的新手,我正在尝试使用 Trirand 的 JQGrid 填充数据库中的数据。当我尝试将数据绑定到 JQGrid 时出现上述错误。

错误在下面一行

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

下面的代码:

 // 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>());
    }

GetListofSAPSPTComponents 方法返回一个 IEnumerable

 IEnumerable<MarketPriceAnalysisModel> GetListOfSAPSPTComponents();

我只是认为错误源是 Trirand.Web.MVC 并且堆栈跟踪说

`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

`

不知道这可能是什么原因?谢谢

4

1 回答 1

1

当您的 MarketPriceAnalysisModel 具有分配给 jqGrid 的字段而不是属性时,也会出现此错误。

于 2014-03-19T09:30:39.637 回答