我有一个Kendo MVC层次结构网格。我的例子是为了便于阅读而简化。
@(Html.Kendo().Grid<LeagueViewModel>(Model.Leagues)
.Name("grid_#=LeagueTypeId#")
.Columns(columns => { })
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add New League(Window)");
})
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.TemplateName("LeagueEdit")
.Window(w =>
{
w.Position(p => p.Top(200)); // position not working, need to center more vertically
w.Width(800);
}
)
)
.Events(e => e.Edit("leagueEdit"))
.DataSource(dataSource => dataSource
.Server()
.Model(model =>
{
model.Id(p => p.LeagueID);
model.Field(l => l.strSportId).DefaultValue("#=SportId#"); // set default value with parent grid data
model.Field(l => l.strLeagueTypeId).DefaultValue("#=LeagueTypeId#"); // set default value with parent grid data
}
)
.Read(read => read.Action("Bound_League_Read", "Configuration", new { _leagueTypeId = "#=LeagueTypeId#" }))
.Create(create => create.Action("League_Create", "Configuration"))
)
)
这是我的javascript事件处理程序。在单击创建按钮后从处理程序中观察e.model对象时,i具有我之前在网格中使用DefaultValue(“#= ParentProperty#”)设置的默认值。
function leagueEdit(e) {
// setting these with default value on model,
// had to have string variants to pass over because template expression syntax
e.model.SportId = parseInt(e.model.strSportId);
e.model.LeagueTypeId = parseInt(e.model.strLeagueTypeId);
}
LeagueEdit.cshtml 当我的弹出模板打开时,模型没有数据。如何将数据导入模型?我在弹出编辑器中有需要父网格值的元素。
<p>sport: @Model.SportId</p> <!-- value does not carry over -->
<p>leaguetype: @Model.LeagueTypeId</p> <!-- value does not carry over -->
答案 0 :(得分:1)
在Edit事件中尝试使用其Id在弹出窗口中查找控件并设置值。例如,在下面的代码中,我在弹出窗口中找到了一个datepicker,并将其值设置为model属性。
function LeagueEditEdit(e) {
var val1 = e.container.find("input[name=CallDate]").data("kendoDatePicker");
val1.value($('#CallDate').attr('value'));
e.model.CallDate = val1._value;
}