This is a migrated thread and some comments may be shown as answers.

Grid not populating data

2 Answers 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jayashree
Top achievements
Rank 1
Jayashree asked on 17 Oct 2013, 06:09 AM
   Hi All,

   I'm new to KendoUI so please bear with me. I've a Kendo gird on a view as below:

   @(Html.Kendo().Grid<VehicleDetails>()
        .Name("grdVehicleDetails")
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .Model(model => model.Id(obj => obj.VehicleID))
            .Read(read => read.Action("ReadVehicleDetails", "Detail"))
        )
        .Columns(columns =>
            {
                columns.Bound(p => p.VehicleNo).Title("Vehicle Number").Width(200);
                columns.Bound(p => p.VehicleBrand).Title("Brand name").Width(200); ;
                columns.Bound(p => p.VehicleTypeCode).Title("Vehicle type").Width(200);
                columns.Bound(p => p.VehicleColor).Title("Vehicle Colour").Width(200); 
            }
        )
        .ColumnMenu()
        .Filterable()
        .Pageable()
        .Sortable(Sortable => Sortable.AllowUnsort(true).SortMode(GridSortMode.SingleColumn))
        .Resizable(resize => resize.Columns(true))
        .Reorderable(reorder => reorder.Columns(true))
        



and controller code is 


   public ActionResult ReadVehicleDetails()
        {
               JsonResult jsonResult = null;

                using (HttpClient httpClient = new HttpClient())
             {
             
                tskResponse = (httpClient.PostAsJsonAsync(Utility.Utility.GetServiceConnectionUri() + "Detail" + "/GetVehicleDetails", vehicleDetails));

                 if (!tskResponse.IsFaulted)
                 {
                     HttpResponseMessage response = tskResponse.Result;

                     response.EnsureSuccessStatusCode();

                     string data = response.Content.ReadAsStringAsync().Result;

                     IEnumerable<VehicleDetails> lstValue = new List<VehicleDetails>();

                     lstValue = JsonConvert.DeserializeObject<IEnumerable<VehicleDetails>>(data);

                     jsonResult = Json(lstValue, JsonRequestBehavior.AllowGet);
                 }
             }
            return jsonResult;
        }

       and json data what I am receiving is in this from 


[{"VehicleID":"a1e5c8a1-2edc-4b52-9080-61f1e2cde35b","CardHolderID":"00000000-0000-0000-0000-000000000000","VehicleTypeCode":"4W","VehicleNo":"456217879","ChasisNo":null,"VehicleColor":"Red","VehicleBrand":"Msruti","IsInsured":false,"InsuranceValidityDate":"\/Date(-62135596800000)\/","CreatedDt":"\/Date(-62135596800000)\/","ModifiedDt":"\/Date(-62135596800000)\/"},

{"VehicleID":"16791925-4510-44b9-87a8-86843fbf1dc6","CardHolderID":"00000000-0000-0000-0000-000000000000","VehicleTypeCode":null,"VehicleNo":null,"ChasisNo":null,"VehicleColor":null,"VehicleBrand":null,"IsInsured":false,"InsuranceValidityDate":"\/Date(-62135596800000)\/","CreatedDt":"\/Date(-62135596800000)\/","ModifiedDt":"\/Date(-62135596800000)\/"},

{"VehicleID":"c849aedb-7612-4706-95a6-8b6ad17c0dd4","CardHolderID":"00000000-0000-0000-0000-000000000000","VehicleTypeCode":"4W","VehicleNo":"456217879121","ChasisNo":null,"VehicleColor":"Red","VehicleBrand":"Maruti","IsInsured":false,"InsuranceValidityDate":"\/Date(-62135596800000)\/","CreatedDt":"\/Date(-62135596800000)\/","ModifiedDt":"\/Date(-62135596800000)\/"},

{"VehicleID":"a0d19492-fefe-4fbc-9e4d-8be203b65b3f","CardHolderID":"00000000-0000-0000-0000-000000000000","VehicleTypeCode":"4W","VehicleNo":"1234567895461","ChasisNo":null,"VehicleColor":"Red","VehicleBrand":"Mahindra","IsInsured":false,"InsuranceValidityDate":"\/Date(-62135596800000)\/","CreatedDt":"\/Date(-62135596800000)\/","ModifiedDt":"\/Date(-62135596800000)\/"},

{"VehicleID":"2e88a5cd-f618-4b0b-ada6-ae402746b163","CardHolderID":"00000000-0000-0000-0000-000000000000","VehicleTypeCode":"2W","VehicleNo":"13213","ChasisNo":null,"VehicleColor":"white","VehicleBrand":"maruthi","IsInsured":false,"InsuranceValidityDate":"\/Date(-62135596800000)\/","CreatedDt":"\/Date(-62135596800000)\/","ModifiedDt":"\/Date(-62135596800000)\/"},

{"VehicleID":"4c805d81-42af-4b93-b54f-afd05ddbead5","CardHolderID":"00000000-0000-0000-0000-000000000000","VehicleTypeCode":"4W","VehicleNo":"123asdasd4asdasd","ChasisNo":null,"VehicleColor":"Red","VehicleBrand":"Maruti","IsInsured":false,"InsuranceValidityDate":"\/Date(-62135596800000)\/","CreatedDt":"\/Date(-62135596800000)\/","ModifiedDt":"\/Date(-62135596800000)\/"}]


Please can someone kindly point out where i'm going wrong.

Many Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Oct 2013, 09:00 AM
Hello,

Please try with the below code snippet.
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

public ActionResult ReadVehicleDetails([DataSourceRequest] DataSourceRequest request)
{
    List<VehicleDetails> lstValue = new List<VehicleDetails>();
 
    using (HttpClient httpClient = new HttpClient())
    {
 
        tskResponse = (httpClient.PostAsJsonAsync(Utility.Utility.GetServiceConnectionUri() + "Detail" + "/GetVehicleDetails", vehicleDetails));
 
        if (!tskResponse.IsFaulted)
        {
            HttpResponseMessage response = tskResponse.Result;
 
            response.EnsureSuccessStatusCode();
 
            string data = response.Content.ReadAsStringAsync().Result;
 
            lstValue = JsonConvert.DeserializeObject<IEnumerable<VehicleDetails>>(data);
 
        }
    }
 
    return Json(lstValue.ToDataSourceResult(request));
}


Thanks,
Jayesh Goyani
0
Jayashree
Top achievements
Rank 1
answered on 17 Oct 2013, 10:08 AM
Thanks a lot that solved my problem.
Tags
Grid
Asked by
Jayashree
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jayashree
Top achievements
Rank 1
Share this question
or