【问题标题】:How to bind list of another list to telerik grid in mvc如何将另一个列表的列表绑定到 mvc 中的 Telerik 网格
【发布时间】:2016-02-08 21:07:22
【问题描述】:

我真的被困在这里了。 如何在 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 网格?如何绑定到列?如何显示数据?

【问题讨论】:

    标签: asp.net-mvc telerik


    【解决方案1】:

    请使用以下代码从另一个列表绑定列表。

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

    网格视图

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 2011-03-29
      • 2018-09-22
      • 1970-01-01
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多