mvc grid ajax read problem!

Jun 15, 2012 at 4:24 AM
Edited Jun 15, 2012 at 4:24 AM

My Well Entity:

public class Well : EntityBase
    {
        public string Code { get; set; }
        public virtual Region Region { get; set; }
    }

Code:

public ActionResult Wells_Read([DataSourceRequest]DataSourceRequest request)
        {
            var  wells = _unitOfWork.WellRespository.Get();
            var result = wells.ToDataSourceResult(request);
            return Json(result);
        }

Html:

@(Html.Kendo().Grid<Mrjiou.Entities.Well>()
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(r => r.Code);           
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .Read(read => readAction("Wells_Read", "Well"))
        )
        .Pageable()
)

I use code first. My problem is when the "Well" entity has the "region" property,

Wells_Read load the data successfully, but can't show in the grid.

if i remove the "Region" property, only keep some types of int,string property, the result can show in the grid. What's the problem? thanks!

 

Coordinator
Jun 18, 2012 at 1:11 PM


Hi mrjiou,

I think what you can do is use a template for the region.  For example, if the region is defined as follows:

public class Region : EntityBase
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }



Then you could do the following in your grid:


@(Html.Kendo().Grid<Mrjiou.Entities.Well>()
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(r => r.Code);          
            columns.Bound(r => r.Region).ClientTemplate("#=Region.Name#")
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .Read(read => readAction("Wells_Read", "Well"))
        )
        .Pageable()
)

Let me know how this turns out for you.

Regards,

John DeVight