您好,我正在嘗試添加自定義下拉列表到Kendoui MVC網格。網格的所有例子都顯示瞭如何用外鍵關係做到這一點。我們是對數據執行操作的下拉菜單(查看詳細信息,編輯信息,刪除記錄),因此與數據無關。所以在我的Index.aspx有:Kendoui Grid自定義下拉框
<% Html.Kendo().Grid<Training.Models.TrainingViewManagementModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(x => x.SelectAction).Width(95).Title("Select Action").ClientTemplate("#=SelectAction#");
columns.Bound(x => x.Record).Width(100);
columns.Bound(x => x.Code).Width(65);
columns.Bound(x => x.PeopleTrained).Width(75);
columns.Bound(x => x.TrainingTypes).Width(100);
columns.Bound(x => x.Trainer).Width(100);
columns.Bound(x => x.TrainingDate).Format("{0:MM/dd/yyyy}").Width(100);
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:500px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.Read("RetrieveTrainingManagementGrid", "Home")
.Model(m =>
{
m.Id(x => x.TrainingID);
m.Field(x => x.SelectAction).Editable(true);
m.Field(x => x.Record).Editable(false);
m.Field(x => x.Code).Editable(false);
m.Field(x => x.PeopleTrained).Editable(false);
m.Field(x => x.TrainingTypes).Editable(false);
m.Field(x => x.Trainer).Editable(false);
m.Field(x => x.TrainingDate).Editable(false);
})
).Render();
%>
然後由於樣本代碼,我有以下編輯模板:
<%=Html.Kendo().DropDownListFor(m=>m)
.Name("SelectAction")
.Events(e=>e.Change("onGridchange"))
.DataTextField("DropDownName")
.DataValueField("DropDownID")
.DataSource(datasource =>datasource
.Read("RetrieveDropdownOptionsKendo", "Home"))
%>
然後在模型中我肯定我在傳遞正確的數據
public IEnumerable<TrainingViewManagementModel> RetrieveAirportManagementView()
{
return new List<TrainingViewManagementModel>()
{
new TrainingViewManagementModel {
SelectAction = new List<DropDownOptions> { new DropDownOptions { DropDownID = 0, DropDownName = "Select an action"}},
TrainingID = 561,
Record = "2001-xxx",
ID = 206,
Code = "BMW",
PeopleTrained = 0,
TrainingTypes = "SCRUM, Hi",
UserID = new Guid(),
Trainer = "John dowle",
TrainingDate = DateTime.Parse("2009-11-21"),
IndividualPeople = "Bob Jim, Jim bob, Jane Bob"
}
};
}
當我運行代碼,我得到下拉列此[對象的對象。我知道我錯過了一些東西,但是我收到了來自樣本和文檔的相互矛盾的信息。提前致謝。