获取kendo网格层次结构中子网格中列的值

时间:2014-03-07 20:54:43

标签: model-view-controller kendo-grid kendo-asp.net-mvc

我有一个Kendo网格层次结构,并且想知道如何获取子网格中列的值,以便我可以将该值传递给控制器​​中的函数。父网格中的数据是从一个db表中提取的,这是一个引用条目,子网格从另一个表中提取,该表包含引用的行项目版本。在子网格中,我单击编辑按钮将值传递给控制器​​。我收到一个错误,说明VersionID未定义。如何从子网格中的VersionID列获取值?

以下是父网格的代码:

@(Html.Kendo().Grid<myWilmer.Models.QuotesSearchViewModel>()
            .Name("quotesSearchGrid")
            .Columns(columns =>
            {
                columns.Bound(c => c.AccountNumber);
                columns.Bound(c => c.QuoteNumber);
                columns.Bound(c => c.CustomerName);
                columns.Template(c => { }).ClientTemplate(
                    Html.ActionLink("Create Version", "CreateQuoteVersion", new { id = "#= QuoteNumber #" }, new { @class = "k-button" }).ToHtmlString());
            })
            .ToolBar(toolbar => toolbar.Custom().Text("Create New Quote").Action("Index", "Quotes"))
            .Selectable(selectable => selectable
                    .Mode(GridSelectionMode.Single))
            .Sortable()
            .ClientDetailTemplateId("template")
            .Events(events => events.DataBound("onDataBound"))
            .Pageable(pageable => pageable
                .ButtonCount(5)
                .PageSizes(new int[] { 10, 20, 30 }))
            .Navigatable()
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(10)
                .Model(model => 
                {
                    model.Id(m => m.QuoteNumber);
                    model.Field(m => m.AccountNumber).Editable(false);
                    model.Field(m => m.QuoteNumber).Editable(false);
                    model.Field(m => m.CustomerName).Editable(false); 
                })
                .Read(read => read.Action("Quotes_Read", "Quotes").Data("filters"))
                .Events(e => e.Error("ShowAjaxError"))
                .Create(update => update.Action("EditingInline_Create", "Quotes"))
            )
)

以下是子网格的代码:

<script id="template" type="text/kendo-templ">
    @(Html.Kendo().Grid<myWilmer.Models.QuoteVersionViewModel>()
        .Name("quoteDetailsGrid_#=QuoteNumber#")
        .Columns(columns =>
        {
            columns.Bound(c => c.VersionID);
            columns.Bound(c => c.JobType);
            columns.Bound(c => c.ProductType);
            columns.Bound(c => c.RepName);
            columns.Bound(c => c.TimeIn).Format("{0:hh:mm:ss tt}");
            columns.Bound(c => c.DateIn).Format("{0:MM/dd/yyyy}");
            columns.Template(c => { }).ClientTemplate(
                    Html.ActionLink("Edit", "Edit", new { id = "#= QuoteNumber #", itemID = "#= VersionID #" }, new { @class = "k-button" }).ToHtmlString());
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(5)
            .Read(read => read.Action("Versions_Read", "Quotes", new { quoteNumber = "#=QuoteNumber#" }))
            .Model(model => {
                model.Id(m => m.VersionID);
                model.Field(m => m.VersionID).Editable(false);
                model.Field(m => m.JobType).Editable(false);
                model.Field(m => m.ProductType).Editable(false);
                model.Field(m => m.RepName).Editable(false);
                model.Field(m => m.TimeIn).Editable(false);
                model.Field(m => m.DateIn).Editable(false);
            })
        )
        .Pageable(pageable => pageable
            .ButtonCount(5)
            .PageSizes(new int[] { 10, 20, 30 }))
        .Sortable()
        .ToClientTemplate()
   )

这是控制器方法

public ActionResult Edit(string id, int itemID)
{
     //Functionality
}

提前致谢 - 肖恩

2 个答案:

答案 0 :(得分:4)

您应该使用:

\\#= VersionID\\#

在子网格中。

答案 1 :(得分:0)

这是我们提出的解决方案。在视图模型中,我们创建了一个名为&#34; EditButton&#34;并将其设置为带有HTML标记的字符串:

QuoteVersionViewModel qvvm = new QuoteVersionViewModel()
                {
                    QuoteNumber = deet.QuoteNum,
                    VersionID = deet.VersionID,
                    ProductType = deet.ProductType,
                    JobType = deet.JobType,
                    RepName = deet.RepName,
                    TimeIn = deet.TimeIn,
                    DateIn = deet.DateIn,
                    EditButton = "<a href='" +u.Action("Edit", "Quotes", new { id = deet.QuoteNum, versionID = deet.VersionID }) + "' class='k-button'>Edit</a>"
                };

我们的Kendo网格栏看起来像这样:

.Columns(columns =>
        {
            columns.Bound(c => c.QuoteNumber);
            columns.Bound(c => c.VersionID);
            columns.Bound(c => c.JobType);
            columns.Bound(c => c.ProductType);
            columns.Bound(c => c.RepName);
            columns.Bound(c => c.TimeIn).Format("{0:hh:mm:ss tt}");
            columns.Bound(c => c.DateIn).Format("{0:MM/dd/yyyy}");
            columns.Bound(c => c.EditButton).Encoded(false);
        })