Parameters kendo mvc razor网格的内联编辑,如何在调用action方法时通过下拉式EditorFor模板发送额外的唯一参数

Parameters kendo mvc razor网格的内联编辑,如何在调用action方法时通过下拉式EditorFor模板发送额外的唯一参数,parameters,kendo-ui,kendo-dropdown,inline-editing,editorfortemplate,Parameters,Kendo Ui,Kendo Dropdown,Inline Editing,Editorfortemplate,我正在使用剑道mvc剃须刀网格 版本:2015.1.408.545 我正在提供内联编辑。 其中有一列有下拉列表,它是通过像这样的模板编辑器绑定的 @(Html.Kendo().DropDownList() .Name("ParentGraphicsCategoryID").HtmlAttributes(new { @style = "font-size:12px", id = "ParentGraphicsCategoryID" }) .DataT

我正在使用剑道mvc剃须刀网格

版本: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");
                });
            }))
问题是:在上述代码中调用“GetGraphicCategories”操作方法时,如何传递一个额外的参数,如id,它对于每一行都是唯一的?

通过以下链接:

这是在上面的url代码中建议的。但在“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")))
@(Html.Kendo().Grid())
.Name(“GraphicsCategory”)
.列(列=>
{
columns.Bound(a=>a.GraphicsCategoryName).Title(“图形类别名称”).Width(150);
columns.Bound(a=>a.ParentGraphicsCategoryName).EditorTemplateName(“parentGraphicsCategoryList”).Title(“父图形类别名称”).Width(150);
columns.Command(Command=>{Command.Edit();}).Title(“Actions”).Width(70);
})
.ToolBar(ToolBar=>ToolBar.Create())
.Editable(可编辑=>Editable.Mode(GridEditMode.InLine))
.Pageable(Pageable=>Pageable.Enabled(true))
.DataSource(DataSource=>DataSource
.Ajax()
.页面大小(10)
.Events(Events=>{Events.Error(“Error_handler”);})
.ServerOperation(真)
.Model(Model=>
{
Id(p=>p.GraphicsCategoryID);
model.Field(p=>p.GraphicsCategoryID).可编辑(false);
})
.Create(update=>update.Action(“InsertOrUpdateGraphicsCategory”、“GraphicsCategories”))
.Update(Update=>Update.Action(“InsertOrUpdateGraphicsCategory”、“GraphicsCategories”))
.Destroy(update=>update.Action(“deleteAdminAreaOwnery”、“adminAreaOwnery”))
.Read(Read=>{Read.Action(“GetAllGraphicsCategories”,“GraphicsCategories”);Read.Type(HttpVerbs.Get);})
).Events(p=>p.DataBound(“generalColumnBound”))

无法在getParentID()中获取行和网格的原因是您使用的是内联编辑模式

在内联编辑模式下,event.srcement是编辑按钮。但是,当您单击按钮进入编辑模式时,剑道会从DOM中删除编辑按钮。因此,当您进入getParentID()时,按钮已不存在,$(event.srcElement)无法再返回按钮,因此无法从中找到任何.closest()元素来查找行和网格

它在链接示例中起作用的原因是,它们使用的是InCell编辑模式,其中event.srcelment将是DropDownList,它仍然在getParentID()内的DOM中,而.closest()将起作用,等等

一个简单的解决方案是在当前技术应该工作的地方使用InCell编辑。假设你不想那么做

您可以尝试更改getParentID(),使其使用网格定义(而不是使用DropDownList/EditorTemplate),并按如下方式实现:

function getParentID() {
    var grid = $("#GraphicsCategory").getKendoGrid();
    var row = $("#GraphicsCategory").find("tr.k-grid-edit-row");
    var dataItem = grid.dataItem(row);

    return ...
}
这取决于知道您所处的特定网格(这就是为什么需要使用网格定义该网格),然后根据k-Grid-edit-row类查找正在编辑的行,当kendo将其置于编辑模式时,k-Grid-edit-row类应用于当前行


还有其他更通用的方法(不要求每个网格都有一个getParentID()),但它们涉及到使用更多的javascript来为列指定一个自定义编辑器,而不是MVC/Razor EditorTemplate,我不确定您是否愿意这样做。

我还没有解决方案,但我知道问题是什么……您使用的是内联编辑,而您链接到的示例使用的是InCell编辑。因此,在getParentID()event.srcElement中是编辑按钮…一旦编辑开始,它就会被移除并替换为更新/取消按钮。因此,它上的最近点()不会返回任何内容(因为不能将最近点的内容返回为零)。在InCell模式下,event.srcelment是DropDownList,因此.closest()将按预期返回行/网格。
function getParentID() {
    var grid = $("#GraphicsCategory").getKendoGrid();
    var row = $("#GraphicsCategory").find("tr.k-grid-edit-row");
    var dataItem = grid.dataItem(row);

    return ...
}