我试图让含有剑道MVC电网等元素提交表单。
- 视图模型包含包含三个字符串字段和
IEnumerable
集合。 - 网格是服务器的约束。 我不加入任何元素或使用网格从列表中删除的任何元素,但电网包含映射到列表中的项目的布尔栏的复选框。
每当我提交此表三种元素在后方法中返回,但名单总是空。
下面是数据模型:
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; }
}
这是我的看法:
@{
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>
当我提交表单,我得到父项背视图模型,但IEnumerable
从电网领域总是空。
这只是没有做到这一点的方式,如果有什么要完成这样的事情呢? 我曾在以前的版本Telerik的这个问题,我认为这是对剑道UI一样。 任何方向将不胜感激。 这是一个长期持续的问题。