Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
375
Error message when binding to data source using Linq
posted

Hi, I'm trying to get my grid to bind to a Linq to Entity Framework data source, but I'm getting an error in the Javascript (attached).

I'm using MVC, and have set up the data model to use remote filtering, paging, grouping and sorting. The controller is set up as follows. Please note that the method GetLinqPagingGridModel simply returns a suitable grid model with the DataSourceUrl set to the LinqInfragisticsGrid action method. The DataSource property for the GridModel doesn't get set.

public ActionResult LinqInfragistics()
{

    GridModel model = InfragisticsGridHelper.GetLinqPagingGridModel(GRID_ID, "ID", Url.Action("LinqInfragisticsGrid"));
    AddInfragisticsGridColumns(model);
    return View("Infragistics", model);
}

[GridDataSourceAction]
public ActionResult LinqInfragisticsGrid()
{
    // Returns the data model as an IQueryable object (required by the grid's data source).
    return View("Infragistics", GetMediaGridDataViaLinq());
}

private IQueryable<MediaBrowserViewModel> GetMediaGridDataViaLinq()
{
    var dataModel = new DataModel();
    IQueryable<MediaBrowserViewModel> model =
        dataModel.tblMedias.Where(
        m => m.IsSystem == "N" || (m.LogicalID >= 0xFFD8 && m.LogicalID <= 0xFFDF) || (m.LogicalID >= 0xFFD0 && m.LogicalID <= 0xFFD7))
        .Select(
            m => new MediaBrowserViewModel
            {
                ID = (long)m.ID,
               LogicalID = (long)m.LogicalID,
               Description = m.Description,
               Option1 = "1",
               Option2 = "2"
           });
    return model;
}

The grid rendering in the razor view is very simple, and looks like -

@(Html.Infragistics().Grid(Model))

Any thoughts on what I'm doing wrong? I'm not getting any errors when I get the data from a stored procedure.

  • 23953
    Suggested Answer
    Offline posted

    Hi Stephen,

    GridDataSourceAction attribute is used in combination with Chaining, so it is not applicable in your scenario.

    When you're using GridModel class you should use GridModel.GetData() method to return the data.

    I've attached an example which demonstrates this.

    Notice that the GetGridModel configures the GridModel instance to use DataSourceUrl. In GetData method I explicitly set DataSource with the actual data. Otherwise nothing will happen.

     

    If you have any questions, don't hesitate to ask.

     

    Best regards,
    Martin Pavlov

    Infragistics, Inc.

    GridModel_DataBinding.zip
  • 645
    Offline posted

    In internet explorer, press F12 to get the developer tools.  Now choose network and start capturing.

    Refresh the page in your browser.

    Now go back to the developer tools and look at the request list.  there will be one to your LinqInfragisticsGrid controller, probably with a status of 500

    Double click this and now choose the response body tab.

    There is likely to be an HTML error message telling you what really went wrong.