如何在剑道UI中绑定列表属性模型.净MVC

本文关键字:属性 列表 模型 MVC 绑定 UI | 更新日期: 2023-09-27 18:16:09

我正在尝试使用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网格模型中使用列表。

谢谢

如何在剑道UI中绑定列表属性模型.净MVC

你没有列出你得到的错误或者你实际得到的结果所以我假设你得到的是视图编译错误

'UserViewModel'不包含'LastLoginDate'和没有扩展方法'LastLoginDate'接受类型的第一个参数'UserViewModel'可以找到(您是否缺少使用指令或程序集引用?)

你的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>