h5s5 February 2016

How to bind list of another list to telerik grid in mvc

I really got stuck here. How do I bind a list of another list data to Telerik grid in MVC?

Example:

public class GetTripDetailsResponse
{
    public DateTime PersonalDriveDate { set; get; }
    public List<AllDrivesInfo> AllDrives { set; get; }
}

public class AllDrivesInfo
{
    public int TripId { set; get; }
    public string Time { set; get; }
    public string Where { set; get; }
    public decimal Miles { set; get; }
    public decimal Value { set; get; }
    public string Purpose { set; get; }
}

Now how to bind it to Telerik grid? How to bind to columns? How to display data?

Answers


Deepak Kushvah February 2016

Please use below code to bind the list from another list.

 public ActionResult GetDrivesInfo()
        {

            List<AllDrivesInfo> AllDrives = null;

            var objDrive = new AllDrivesInfo { TripId = 1, Time = "Time", Where = "where", Miles = 10, Value = 20, Purpose = "my purpose" }; //Get Code here

            foreach (AllDrivesInfo d in objDrive)
            {

                AllDrives.Add(new AllDrivesInfo { TripId = d.TripId, Time = d.Time, Where = d.Where, Miles = d.Miles, Value = d.Value, Purpose = d.Purpose });
            }

        }

Bind Telerik GridView

You need to return Json result to bind the gridview:

 public ActionResult Drives_Get([DataSourceRequest] DataSourceRequest request)
        {
             //Bind "DrivesList" here
            return Json(DrivesModel.DrivesList.ToDataSourceResult(request));
        }

Gridview

.Read(read => read.Action("Drives_Get", "Drives"))

Post Status

Asked in February 2016
Viewed 3,242 times
Voted 10
Answered 1 times

Search




Leave an answer