问题描述
我想获得包含telekik MVC电网等元素提交表单。
I am trying to get a Form containing a telekik MVC grid and other elements to submit.
- 视图模型包含包含三个字符串字段和
的IEnumerable
集合。 - 网格是服务器的约束。我不添加任何元素或使用网格删除列表中的任何元素,但网格包含映射到列表中的项目的布尔列的复选框。
在以往我提交此表三串元素后返回的方法列表,但始终为空。
When ever i submit this form the three string elements return in the post method but list is always 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;}
}
这是我的观点:
@{
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>
当我提交表单,我得到父母的项背视图模型,但是从电网Inumerable域总是空。
WHen i submit the form I get the parents items back in the view model but the Inumerable fields from the grid are always null..
时要做到这一点这只是没有办法的办法,如果那么什么是acommplish像这样的方式。我已经对previous Telerik的版本这个问题,我认为这是对剑道的UI一样。任何方向将大大AP preciated。这一直是沿问题下去。
Is this just not the way to do this and if so what is the way to acommplish something like this. I have had this issue on previous telerik versions and I see it is the same on Kendo UI. Any direction would be greatly appreciated. This has been along going on issue.
推荐答案
我正好有这个场景在我的项目完美的工作。这里是我的网声明...
I have exactly this scenario working perfectly in my project. Here's my grid declaration...
@(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()
)
这里的索引功能:
Here's the "index" function:
function index(dataItem) {
var data = $("#RequestLinesGrid").data("kendoGrid").dataSource.data();
return data.indexOf(dataItem);
}
这篇关于提交表单与剑道MVC电网等元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!