use*_*808 14 asp.net-mvc grid user-interface post kendo-ui
我正在尝试获取包含Kendo MVC网格和其他要提交的元素的表单.
IEnumerable
集合. 每当我提交此表单时,三个字符串元素在post方法中返回,但列表始终为null.
这是数据模型:
public class Parent
{
public string Field1 { get; set; }
public string Field2 { get; set; }
public string Comments { get; set; }
public IEnumerable<ChildItems> Children { get; set; }
}
public class ChildItems
{
public string ChildField1 { get; set; }
public string ChildField2 { get; set; }
public boolean Include { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的观点:
@{
ViewBag.Title = "Index";
}
@model GridInForm.Models.Parent
@using(Html.BeginForm("Save", "Home"))
{
<fieldset>
<legend>Editing Parent</legend>
@Html.LabelFor(parent => parent.Field1)
@Html.EditorFor(parent => parent.Field1)
@Html.LabelFor(parent => parent.Field2)
@Html.EditorFor(parent => parent.Field2)
@Html.LabelFor(parent => parent.Comments)
@Html.EditorFor(parent => parent.Comments)
@(Html.Kendo().Grid(Model.Children)
.Name("Children")
.ToolBar(tools => tools.Create().Text("Add new Children"))
.Editable(editable => editable.Mode(GridEditMode.PopUp).CreateAt(GridInsertRowPosition.Bottom))
.Columns(columns =>
{
columns.Bound(p => p.ChildField1).ClientTemplate("#= ChildField1 #" +
"<input type='hidden' name='ChildField1[#= index(data)#].ChildField1' value='#= Name #' />"
);
columns.Bound(p => p.ChildField2).Hidden().ClientTemplate("#= ChildField1 #" +
"<input type='hidden' name='ChildField1[#= index(data)#].ChildField1' value='#= ChildField1 #' />"
);
columns.Command(command =>
{
// command.Destroy();
command.Edit();
}).Width(100);
})
.DataSource(dataSource => dataSource
.Server()
.Create("Create", "Home")
.Read("Index", "Home")
.Update("Update", "Home")
.Model(model =>
{
model.Id(p => p.ChildField1);
model.Field(p => p.ChildField1).Editable(false);
})
//.ServerOperation(true)
)
)
</fieldset>
<input type="submit" value="Save" />
}
<script>
function index(dataItem) {
alert("bindind");
var data = $("#Products").data("kendoGrid").dataSource.data();
return data.indexOf(dataItem);
}
</script>
Run Code Online (Sandbox Code Playgroud)
当我提交表单时,我在视图模型中返回父项,但IEnumerable
网格中的字段始终为null.
这不是这样做的方式,如果是这样,那么完成这样的事情的方法是什么?我在以前的Telerik版本上遇到过这个问题,我发现它在Kendo UI上是相同的.任何方向将不胜感激.这是一个长期存在的问题.
我确实这个场景在我的项目中完美运行.这是我的网格声明......
@(Html.Kendo().Grid(Model.ChildLines)
.Name("RequestLinesGrid")
.Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InCell))
.Columns(columns =>
{
columns.Bound(p => p.ItemCode).ClientTemplate("#= ItemCode #" +
"<input type='hidden' name='MyLines[#= index(data)#].ItemCode' value='#= ItemCode #' />"
);
columns.Bound(p => p.Description).ClientTemplate("#= Description #" +
"<input type='hidden' name='MyLines[#= index(data)#].Description' value='#= Description #' />"
);
columns.Bound(p => p.UoM).ClientTemplate("#= UoM #" +
"<input type='hidden' name='MyLines[#= index(data)#].UoM' value='#= UoM #' />"
);
columns.Bound(p => p.QtyCC).ClientTemplate("#= QtyCC #" +
"<input type='hidden' name='MyLines[#= index(data)#].QtyCC' value='#= QtyCC #' />"
);
columns.Bound(p => p.QtyEmployee).ClientTemplate("#= QtyEmployee #" +
"<input type='hidden' name='MyLines[#= index(data)#].QtyEmployee' value='#= QtyEmployee #' />"
);
columns.Bound(p => p.ItemListLineID).Hidden(true).ClientTemplate("#= ItemListLineID #" +
"<input type='hidden' name='MyLines[#= index(data)#].ItemListLineID' value='#= ItemListLineID #' />"
);
columns.Bound(p => p.ItemListCode).Hidden(true).ClientTemplate("#= ItemListCode #" +
"<input type='hidden' name='MyLines[#= index(data)#].ItemListCode' value='#= ItemListCode #' />"
);
columns.Command(command =>
{
command.Destroy();
}).Width(200);
})
.DataSource(dataSource => dataSource.Ajax()
.Model(m =>
{
m.Id(p => p.ItemCode);
m.Field(p => p.ItemCode).Editable(false);
m.Field(p => p.Description).Editable(false);
m.Field(p => p.UoM).Editable(false);
m.Field(p => p.QtyCC).Editable(true);
m.Field(p => p.QtyEmployee).Editable(true);
m.Field(p => p.ItemListLineID).Editable(false);
m.Field(p => p.ItemListCode).Editable(false);
})
.Batch(true)
.ServerOperation(false)
// these are dummy action methods that don't really exist.
.Update("upd", "upd")
.Destroy("del", "del")
.Create("cre", "cre")
)
.Navigatable()
)
Run Code Online (Sandbox Code Playgroud)
这是"索引"功能:
function index(dataItem) {
var data = $("#RequestLinesGrid").data("kendoGrid").dataSource.data();
return data.indexOf(dataItem);
}
Run Code Online (Sandbox Code Playgroud)