Model view controller Kendo Telerik MVC绑定属性到子网格不起作用
我刚开始使用Telerik Grids,我不知道这是否是正确的方法,但我的老板想在同一个网格中在线编辑数据,现在我遇到了一个问题: 这是我的数据模型:Model view controller Kendo Telerik MVC绑定属性到子网格不起作用,model-view-controller,grid,telerik,Model View Controller,Grid,Telerik,我刚开始使用Telerik Grids,我不知道这是否是正确的方法,但我的老板想在同一个网格中在线编辑数据,现在我遇到了一个问题: 这是我的数据模型: public class InternVM { public int InternId { get; set; } public Guid UserId { get; set; } [Required] [MaxLen
public class InternVM
{
public int InternId { get; set; }
public Guid UserId { get; set; }
[Required]
[MaxLength(50)]
[Display(Name = "User ID")]
public string UserName { get; set; }
[Required]
[MaxLength(50)]
public string LastName { get; set; }
[Required]
[MaxLength(50)]
public string FirstName { get; set; }
[UIHint("Date")]
[Display(Name ="Certified")]
public DateTime? CertifiedDate { get; set; }
public string Status { get; set; }
[UIHint("InternSchedule")]
public List<InternScheduleVM> Schedules { get; set; }
[UIHint("InternAttorneyDDL")]
public List<AttorneyVM> Attorneys { get; set; }
}
公共类InternVM
{
public int InternId{get;set;}
公共Guid用户标识{get;set;}
[必需]
[MaxLength(50)]
[显示(名称=“用户ID”)]
公共字符串用户名{get;set;}
[必需]
[MaxLength(50)]
公共字符串LastName{get;set;}
[必需]
[MaxLength(50)]
公共字符串名{get;set;}
[提示(“日期”)]
[显示(Name=“认证”)]
公共日期时间?CertifiedDate{get;set;}
公共字符串状态{get;set;}
[UIHint(“实习时间表”)]
公共列表计划{get;set;}
[UIHint(“内部律师”)]
公开名单律师{get;set;}
}
我创建了一个主网格,如下所示:
@(Html.Kendo().Grid<InternVM>()
.Name("InternGrid")
.Columns(columns =>
{
columns.Command(command => { command.Edit().Text(" ").CancelText(" ").UpdateText(" "); command.Destroy().Text(" "); })
.Width(100).Locked(true).Lockable(false);
columns.Bound(c => c.InternId).Visible(false);
columns.Bound(c => c.UserName).Width(200);
columns.Bound(c => c.LastName).Width(200);
columns.Bound(c => c.FirstName).Width(200);
columns.Bound(c => c.Attorneys).ClientTemplate("#=DisplayAttorneys(Attorneys)#").Width(200);
columns.Bound(c => c.Status).Width(200);
columns.Bound(c => c.CertifiedDate).Format("{0:dd/MM/yyyy}").Width(200);
columns.Bound(c => c.Schedules).ClientTemplate("#=DisplaySchedules(Schedules)#").Width(700);
})
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(m => {
m.Id(c => c.InternId);
m.Field(c => c.UserId).DefaultValue(Guid.NewGuid());
m.Field(c => c.Attorneys).DefaultValue(new List<AttorneyVM>());
})
.Read(read => read.Action("Read", "Intern"))
.Destroy(destroy => destroy.Action("Destroy", "Intern"))
.Update(update => update.Action("Update", "Intern"))
.Create(create => create.Action("Create", "Intern"))
.Events(events => events.RequestEnd("onRequestEnd"))
)
.ToolBar(toolbar => { toolbar.Create().Text("Add"); })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.HtmlAttributes(new { @style = "height:450px"})
.Events(e => e.BeforeEdit("onBeforeEdit"))
)
@model IEnumerable<InternScheduleVM>
<script>
function onRequestEnd(e) {
if (e.type == "update" || e.type == "create" || e.type == "remove") {
$("#InternScheduleGrid").data("kendoGrid").dataSource.read();
}
}
function onRequestStart(e) {
if (e.type == "read")
//console.log("onRequestStart");
}
function getParentId() {
let parentId = $('#parentIdInput').val();
return {
internId: parentId
};
}
</script>
<p>
</p>
<div>
@(Html.Kendo().Grid(Model)
.Name("InternScheduleGrid")
.Columns(columns =>
{
columns.Command(command => { command.Edit().Text(" ").CancelText(" ").UpdateText(" "); command.Destroy().Text(" "); }).Width(100);
columns.Bound(c => c.InternScheduleID).Visible(false);
columns.Bound(c => c.DayOfWeek);
columns.Bound(c => c.StartTime).Format("{0:HH:mm:ss}");
columns.Bound(c => c.EndTime).Format("{0:HH:mm:ss}");
})
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(m =>
{
m.Id(c => c.InternScheduleID);
})
.Read(read => read.Action("Read", "InternSchedule").Data("getParentId"))
.Destroy(destroy => destroy.Action("Destroy", "InternSchedule"))
.Update(update => update.Action("Update", "InternSchedule"))
.Create(create => create.Action("Create", "InternSchedule").Data("getParentId"))
.Events(events => { events.RequestEnd("onRequestEnd"); events.RequestStart("onRequestStart"); })
)
.ToolBar(toolbar => { toolbar.Create().Text("Add"); })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Events(e => e.Edit("onEdit"))
)
</div>
@(Html.Kendo().Grid())
.名称(“InternGrid”)
.列(列=>
{
columns.Command(Command=>{Command.Edit().Text(“”).CancelText(“”).UpdateText(“”);Command.Destroy().Text(“”;})
.宽度(100).锁定(真).可锁定(假);
columns.Bound(c=>c.InternId).Visible(false);
columns.Bound(c=>c.UserName).Width(200);
columns.Bound(c=>c.LastName).Width(200);
columns.Bound(c=>c.FirstName).Width(200);
columns.Bound(c=>c.Attorneys.ClientTemplate(“#=DisplayAttorneys(Attorneys)#”)。宽度(200);
columns.Bound(c=>c.Status).Width(200);
columns.Bound(c=>c.CertifiedDate).Format(“{0:dd/MM/yyyy}”).Width(200);
columns.Bound(c=>c.Schedules).ClientTemplate(“#=DisplaySchedules(Schedules)#”)。宽度(700);
})
.Scrollable()
.DataSource(DataSource=>DataSource
.Ajax()
.Model(m=>{
m、 Id(c=>c.InternId);
m、 字段(c=>c.UserId).DefaultValue(Guid.NewGuid());
m、 字段(c=>c.Attorneys).DefaultValue(新列表());
})
.Read(Read=>Read.Action(“Read”,“Intern”))
.Destroy(Destroy=>Destroy.Action(“Destroy”、“Intern”))
.Update(Update=>Update.Action(“更新”、“实习”))
.Create(Create=>Create.Action(“Create”、“Intern”))
.Events(Events=>Events.RequestEnd(“onRequestEnd”))
)
.ToolBar(ToolBar=>{ToolBar.Create().Text(“Add”);})
.Editable(可编辑=>Editable.Mode(GridEditMode.InLine))
.HtmlAttributes(新的{@style=“height:450px”})
.Events(e=>e.BeforeEdit(“onBeforeEdit”))
)
其中一个字段使用的是EditorTemplateView,它是另一个网格(明细表),如下所示:
@(Html.Kendo().Grid<InternVM>()
.Name("InternGrid")
.Columns(columns =>
{
columns.Command(command => { command.Edit().Text(" ").CancelText(" ").UpdateText(" "); command.Destroy().Text(" "); })
.Width(100).Locked(true).Lockable(false);
columns.Bound(c => c.InternId).Visible(false);
columns.Bound(c => c.UserName).Width(200);
columns.Bound(c => c.LastName).Width(200);
columns.Bound(c => c.FirstName).Width(200);
columns.Bound(c => c.Attorneys).ClientTemplate("#=DisplayAttorneys(Attorneys)#").Width(200);
columns.Bound(c => c.Status).Width(200);
columns.Bound(c => c.CertifiedDate).Format("{0:dd/MM/yyyy}").Width(200);
columns.Bound(c => c.Schedules).ClientTemplate("#=DisplaySchedules(Schedules)#").Width(700);
})
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(m => {
m.Id(c => c.InternId);
m.Field(c => c.UserId).DefaultValue(Guid.NewGuid());
m.Field(c => c.Attorneys).DefaultValue(new List<AttorneyVM>());
})
.Read(read => read.Action("Read", "Intern"))
.Destroy(destroy => destroy.Action("Destroy", "Intern"))
.Update(update => update.Action("Update", "Intern"))
.Create(create => create.Action("Create", "Intern"))
.Events(events => events.RequestEnd("onRequestEnd"))
)
.ToolBar(toolbar => { toolbar.Create().Text("Add"); })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.HtmlAttributes(new { @style = "height:450px"})
.Events(e => e.BeforeEdit("onBeforeEdit"))
)
@model IEnumerable<InternScheduleVM>
<script>
function onRequestEnd(e) {
if (e.type == "update" || e.type == "create" || e.type == "remove") {
$("#InternScheduleGrid").data("kendoGrid").dataSource.read();
}
}
function onRequestStart(e) {
if (e.type == "read")
//console.log("onRequestStart");
}
function getParentId() {
let parentId = $('#parentIdInput').val();
return {
internId: parentId
};
}
</script>
<p>
</p>
<div>
@(Html.Kendo().Grid(Model)
.Name("InternScheduleGrid")
.Columns(columns =>
{
columns.Command(command => { command.Edit().Text(" ").CancelText(" ").UpdateText(" "); command.Destroy().Text(" "); }).Width(100);
columns.Bound(c => c.InternScheduleID).Visible(false);
columns.Bound(c => c.DayOfWeek);
columns.Bound(c => c.StartTime).Format("{0:HH:mm:ss}");
columns.Bound(c => c.EndTime).Format("{0:HH:mm:ss}");
})
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(m =>
{
m.Id(c => c.InternScheduleID);
})
.Read(read => read.Action("Read", "InternSchedule").Data("getParentId"))
.Destroy(destroy => destroy.Action("Destroy", "InternSchedule"))
.Update(update => update.Action("Update", "InternSchedule"))
.Create(create => create.Action("Create", "InternSchedule").Data("getParentId"))
.Events(events => { events.RequestEnd("onRequestEnd"); events.RequestStart("onRequestStart"); })
)
.ToolBar(toolbar => { toolbar.Create().Text("Add"); })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Events(e => e.Edit("onEdit"))
)
</div>
@model IEnumerable
函数onRequestEnd(e){
如果(e.type==“更新”| | e.type==“创建”| | e.type==“删除”){
$(“#实习生计划网格”).data(“kendoGrid”).dataSource.read();
}
}
函数onRequestStart(e){
如果(例如类型=“读取”)
//log(“onRequestStart”);
}
函数getParentId(){
让parentId=$('#parentIdInput').val();
返回{
internId:parentId
};
}
@(Html.Kendo().Grid(模型)
.Name(“实习生计划表”)
.列(列=>
{
Command(Command=>{Command.Edit().Text(“”).CancelText(“”).UpdateText(“”);Command.Destroy().Text(“”;}).Width(100);
columns.Bound(c=>c.InternScheduleID).Visible(false);
columns.Bound(c=>c.DayOfWeek);
columns.Bound(c=>c.StartTime.Format(“{0:HH:mm:ss}”);
columns.Bound(c=>c.EndTime).Format(“{0:HH:mm:ss}”);
})
.Scrollable()
.DataSource(DataSource=>DataSource
.Ajax()
.Model(m=>
{
m、 Id(c=>c.InternScheduleID);
})
.Read(Read=>Read.Action(“Read”,“internetschedule”).Data(“getParentId”))
.Destroy(Destroy=>Destroy.Action(“Destroy”、“实习生计划”))
.Update(Update=>Update.Action(“更新”、“实习计划”))
.Create(Create=>Create.Action(“Create”、“internetschedule”).Data(“getParentId”))
.Events(Events=>{Events.RequestEnd(“onRequestEnd”);Events.RequestStart(“onRequestStart”);}
)
.ToolBar(ToolBar=>{ToolBar.Create().Text(“Add”);})
.Editable(可编辑=>Editable.Mode(GridEditMode.InLine))
.Events(e=>e.Edit(“onEdit”))
)
子网格运行良好,我将其和模型绑定,但每当我在这个网格中进行更改时,它都不会上载我的模型InternVM。
知道为什么吗?我刚刚使用了一个网格细节模板来传递主视图中的参数。谢谢