我正在使用劍道mvc剃鬚刀網格。在線編輯劍道mvc剃鬚刀網格,如何通過下拉發送額外的獨特參數EditorFor模板,同時調用動作方法
版本:2015.1.408.545。
我正在提供內聯編輯。 在這裏它們是有一個下拉列,它通過編輯器爲這樣的模板綁定。
@(Html.Kendo().DropDownList()
.Name("ParentGraphicsCategoryID").HtmlAttributes(new { @style = "font-size:12px", id = "ParentGraphicsCategoryID" })
.DataTextField("Text")
.OptionLabel("- Select Parent Graphic Category - ")
.DataValueField("Value")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetGraphicCategories", "CommonLookUp");
});
}))
的問題是:如何通過類似ID的附加參數,它是唯一的每一行,當調用上面的代碼「GetGraphicCategories」的操作方法?
通過以下鏈接:http://www.telerik.com/forums/pass-grid-view-model-data-to-editor-template
@(Html.Kendo().DropDownList()
.Name("ParentGraphicsCategoryID").HtmlAttributes(new { @style = "font-size:12px", id = "ParentGraphicsCategoryID" })
.DataTextField("Text")
.OptionLabel("- Select Parent Graphic Category - ")
.DataValueField("Value")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetGraphicCategories", "CommonLookUp").Data("getParentID()");
});
}))
function getParentID() {
var row = $(event.srcElement).closest("tr");
var grid = $(event.srcElement).closest("[data-role=grid]").data("kendoGrid");
var dataItem = grid.dataItem(row);
//where the OrderID is the model ID
return { statusId: dataItem.StatusId } }
它在上述網址的代碼suggeted。但在調用「Data」方法中的「getParentID()」時無法獲取行值,因爲它是通過模板的下拉編輯器調用的。所以網格變量值爲null。
代碼創建網格低於:
@(Html.Kendo().Grid<GraphicsCategoryModel>()
.Name("GraphicsCategory")
.Columns(columns =>
{
columns.Bound(a => a.GraphicsCategoryName).Title("Graphics Category Name").Width(150);
columns.Bound(a => a.ParentGraphicsCategoryName).EditorTemplateName("ParentGraphicCategoryList").Title("Parent Graphics Category Name").Width(150);
columns.Command(command => { command.Edit(); }).Title("Actions").Width(70);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable(pageable => pageable.Enabled(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Events(events => { events.Error("error_handler"); })
.ServerOperation(true)
.Model(model =>
{
model.Id(p => p.GraphicsCategoryID);
model.Field(p => p.GraphicsCategoryID).Editable(false);
})
.Create(update => update.Action("InsertOrUpdateGraphicsCategory", "GraphicsCategories"))
.Update(update => update.Action("InsertOrUpdateGraphicsCategory", "GraphicsCategories"))
.Destroy(update => update.Action("DeleteAdminAreaOwnership", "AdminAreaOwnership"))
.Read(read => { read.Action("GetAllGraphicsCategories", "GraphicsCategories"); read.Type(HttpVerbs.Get); })
).Events(p => p.DataBound("generalColumnBound")))
我還沒有解決方案,但我知道問題是什麼......您正在使用InLine編輯,而您鏈接的示例正在使用InCell編輯。所以,在getParentID()中,event.srcElement是編輯按鈕......只要編輯開始,它就被刪除並且被替換爲更新/取消按鈕。最接近()它沒有返回(因爲你不能返回最接近的東西)。在InCell模式下,event.srcElement是DropDownList,因此.closest()將按預期方式返回行/網格。 –