0
我有一個Kendo MVC層次結構網格。爲了便於閱讀,我的例子被簡化了。模型在彈出Kendo MVC Grid的編輯器模板中爲空創建,沒有默認值
@(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對象時,我使用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 -->