2016-11-03 22 views
1

我想綁定使用Kendo UI Asp.Net MVC Grid的模型中的列表屬性,但我不能。如何綁定到Kendo UI模型中的列表屬性Asp.Net MVC

這裏是我的VieModel:

  var userList = allUsers.Select(p => new UserViewModel 
     { 
      UserId = p.Id, 
      UserName = p.UserName, 
      Name = p.Name, 
      LastName = p.LastName, 
      HospitalCode = p.HospitalCode, 
      HospitalName = p.HospitalName, 
      RelatedHospitals = userHospitals.Where(t => t.UserId == p.Id).Select(x => new Hosp { HospitalId = x.HospitalCode, HospitalName = x.HospitalName }).ToList(), 
      PhoneNumber = p.PhoneNumber, 
      OfficePhone = p.OfficePhone, 
      Email = p.Email, 
      UserRoleName = p.UserRoleName, 
      City = p.CityName, 
      CityTownName = p.CityTownName, 
      UserTracks =context.UserTracks.Where(t=>t.UserId==p.Id).Select(x => new UserTrck { LastLoginDate = x.LastLoginDate, LocalIp = x.LocalIp, LastUsedWebBrowser = x.LastUsedWebBrowser }).ToList(), 
      CreatedDate = p.CreatedDate, 
      UpdatedDate = p.UpdatedDate 
     }); 
     }); 

這裏是我的網格約束,且我嘗試:

columns.Bound(p => p.LastLoginDate).ClientTemplate("#=UserTracks[0].LastLoginDate#").Filterable(false).Sortable(false).Width(220); 

但這不能幫助我。

如何在Kendo UI MVC Grid中使用模型列表。

感謝

回答

0

您還沒有列出你所得到的錯誤或者是什麼導致你實際上得到,所以我會假設你正在沿着

線得到一個查看編譯錯誤「UserViewModel」不包含「LastLoginDate」和 沒有擴展方法的定義「LastLoginDate」接受 類型的第一參數「UserViewModel」可以找到(是否缺少using指令或 程序集引用?)

您的ViewModel似乎沒有LastLoginDate字段。

您不能將網格列綁定到不存在的東西。

要麼直接使LastLoginDate成爲ViewModel的成員,要麼將該列綁定到UserTracks。

columns.Bound(p => p.UserTracks).ClientTemplate("#=lastLoginTemplate(UserTracks)#").Filterable(false).Sortable(false).Width(220); 

<script> 
    function lastLoginTemplate(UserTracks) { 
     return UserTracks[0].LastLoginDate; 
    } 
</script> 
相關問題