Changing from standard view to grid

2 posts, 0 answers
  1. Kevin
    Kevin avatar
    1 posts
    Member since:
    Oct 2014

    Posted 21 Oct 2014 Link to this post

    I have put together a simple app which include a few or the "out-of-the-box" index views. I would like to swap the table in these views for the Telerik grid.

    I have the following action in the controller:

    // GET: Assets
    public ActionResult Index()
    {
         
        var assets = db.Assets.Include(a => a.Equipment).Include(a => a.Owner).Include(a => a.ServiceCompany).Include(a => a.Site);
         
        return View(assets.ToList());
    }

    I have swapped out the table code and copied the following from the demo

    @(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.Site).Title("Site").Width(130);
            columns.Bound(p => p.Location).Title("Location").Width(130);
            columns.Bound(p => p.Description).Title("Decriptopn").Width(130);
            columns.Bound(p => p.InstallDate).Title("Install Date").Width(130);
            columns.Bound(p => p.SerialNo).Title("Serial Number").Width(130);
        })
        .Pageable()
        .Sortable()
        .Scrollable(scr => scr.Height(430))
        .Filterable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .ServerOperation(false)
         )
    )


    When I try to view the 

    System.InvalidOperationException was unhandled by user code
      HResult=-2146233079
      Message=A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.Asset_ED2530D1AC046011EB9F014D634FE570012E36DD19818476965A4BF61659B91A'.
      Source=System.Web.Extensions
     
    I changed the HTML helper line to

    @(Html.Kendo().Grid<AMScan.Models.Asset>()

    which then rendered the grid on the page without the exception however there was no data.

    Can you please tell me what I am doing wrong.
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 23 Oct 2014 Link to this post

    Hi Kevin,


    Regarding the exception, you could take a look at the following documentation page, which describes the reason for it and the common ways to solve it.

    The difference between the two type of helpers is that the one passes the Model as data and then uses it locally on the client side, as the other one requires you to configure a read action, which will return the Grid data.

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top