Kendo ui 当使用Guid数据类型时,KendUI网格外键字段为空
我已经实现了一个Kendo ui 当使用Guid数据类型时,KendUI网格外键字段为空,kendo-ui,telerik,kendo-grid,kendo-asp.net-mvc,kendo-ui-grid,Kendo Ui,Telerik,Kendo Grid,Kendo Asp.net Mvc,Kendo Ui Grid,我已经实现了一个KendoUI网格 以下是视图中的网格实现 @(Html.Kendo().Grid<Example.Web.UI.ViewModels.ExampleItem>() .Name("ExampleGrid") .Columns(columns => { columns.Bound(p => p.Name); columns.Bound(p => p.Label); columns.Bound(p => p.Type);
KendoUI网格
以下是视图中的网格
实现
@(Html.Kendo().Grid<Example.Web.UI.ViewModels.ExampleItem>()
.Name("ExampleGrid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.Label);
columns.Bound(p => p.Type);
columns.Bound(p => p.InputType);
columns.ForeignKey(p => p.ParentId, (System.Collections.IEnumerable)ViewData["items"], "Id", "Name").Title("Parent");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.Id).DefaultValue(Guid.NewGuid());
model.Field(p => p.ParentId).DefaultValue(null);
})
.Create(update => update.Action("EditingPopup_Create", "Example"))
.Read(read => read.Action("EditingPopup_Read", "Example"))
.Update(update => update.Action("EditingPopup_Update", "Example"))
.Destroy(update => update.Action("EditingPopup_Destroy", "Example"))
)
)
在我的控制器中
我设置外键项如下:
ViewData["items"] = exampleItems; // This is a List<ExampleItem>
现在一切都好了。因此,问题是:
为什么外键字段的kendouigrid
与Guid
数据类型不同?有办法解决这个问题吗
我甚至尝试使用字符串
,但也没用
是否需要安装额外的库,以便UI组件更好地与Guid
s配合使用
我需要Id的类型为Guid
,因为可以将记录迁移到其他服务器,并且Id需要唯一。公共Id{get;set;}
。。自从C#拥有数据类型id
?@DionDirza-thanx指出哈哈,修正了它。
ViewData["items"] = exampleItems; // This is a List<ExampleItem>
public class ExampleItem
{
[ScaffoldColumn(false)]
public int Id { get; set; }
public string Name { get; set; }
public string Label { get; set; }
public string Type { get; set; }
[DisplayName("Input Type")]
public string InputType { get; set; }
public ExampleItem Parent { get; set; }
public int? ParentId { get; set; }
}