如何将另一个列表的列表绑定到mvc中的telerik网格

时间:2016-02-08 10:22:01

标签: asp.net-mvc telerik

我真的被困在这里了。 如何将另一个列表数据列表绑定到MVC中的Telerik网格?

示例:

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; }
}

现在如何将其绑定到Telerik网格?如何绑定到列?如何显示数据?

1 个答案:

答案 0 :(得分:0)

请使用以下代码绑定其他列表中的列表。

 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 });
            }

        }

绑定Telerik GridView

您需要返回Json结果以绑定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"))