Kendo Grid hierarchy passing ID from master grid

拟墨画扇 提交于 2019-12-04 05:01:44

问题


I have a Kendo Hierarchial Grid where the master grid contains the Client details and the sub grid contains the Point of Contacts. I am able to pass the Client ID from the master grid into the sub grid Read action and the data is loading fine. However, the issue comes while passing the Client ID into a Add New Point of Contact button in the sub grid. If I hard-code the value the Controller method runs fine. However, it is unable to pick the reference Client ID.

The sub grid is as follows:

<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().Grid<Track24.Billing.Web.Models.ListPointOfContactViewModel>()
.Name("grid_#=ClientID#")
.Columns(columns =>
{
columns.Bound(p => p.POC_ClientID);
columns.Bound(p => p.ContactName);
columns.Bound(p => p.RegionName).Filterable(filterable => filterable.UI("regionFilter"));
columns.Bound(p => p.CountryName).Filterable(filterable => filterable.UI("countryFilter"));
columns.Bound(p => p.ContactEmail);
columns.Bound(p => p.ContactNumber);
})
.ToolBar(toolbar => toolbar.Template(@<text>
<a class="k-button k-button-icontext k-grid-add subgridadd" href="@Url.Action("CreatePOC", "PointOfContact", new { id = "\\#= ClientID\\#" })"><span class="k-icon k-add"></span>Add new Point-of-Contact</a></text>))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read
(
read => read.Action("ClientBinding_PointOfContacts", "PointOfContact", new { clientID = "#=ClientID#" })
)
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>

The sub grid binds correctly with the master grid; hence ClientID is read properly in the sub grid. However, I am unable to read the same in the Add New button.

EDIT 1: This is my main (parent) grid:

<div class="row">
    <div class="box">
        <div class="box-body table-responsive">
            @(Html.Kendo().Grid<Track24.Billing.Web.Models.ListClientViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(e => e.ClientName);
            columns.Template(@<text></text>).ClientTemplate("<a class='btn btn-primary grid-edit' href='" + @Url.Action("EditClient", "PointOfContact", new { id = "#:ClientID#" }) + "'><span class='glyphicon glyphicon-edit'></span>Edit</a> <a class='btn btn-primary' data-href='" + @Url.Action("DeleteClient", "PointOfContact", new { id = "#:ClientID#" }) + "' data-toggle='modal' data-target='\\#confirm-delete' href='\\#' ><span class='glyphicon glyphicon-trash'></span>Delete</a>");

        })
        .Sortable()
        .Pageable()
        .Scrollable()
        .ClientDetailTemplateId("template")
        .HtmlAttributes(new { style = "height:430px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(e => e.ClientID))
            .PageSize(6)
            .Read(read => read.Action("Client_Read", "PointOfContact"))
        )
        .Events(events => events.DataBound("dataBound"))
        .ToolBar(toolbar => toolbar.Template(@<text><a id="btnCreate" class="k-button k-button-icontext k-grid-add" href="@Url.Action("CreateClient", "PointOfContact")"><span class="k-icon k-add"></span>Add new Client</a></text>))


)
        </div>

    </div>
</div>

EDIT 2: I tried passing the link through the Create URL but it gives me an error Cannot perform runtime binding on a null reference

.ToolBar(toolBar =>
                        {
                            toolBar.Create();
                            toolBar.Save();
                        })
                                .DataSource(dataSource => dataSource
                                .Ajax()
                                        .Model(model =>
                                            {

                                                model.Id(p => p.POC_ClientID);
                                            })
                                .PageSize(10)
                                .Read
                                (
                                read => read.Action("ClientBinding_PointOfContacts", "PointOfContact", new { clientID = "#=ClientID#" })
                                )
                                .Create(create => create.Action("CreatePOC", "PointOfContact", new { pclientID = Model.Id }))
                                )
                                .Pageable()
                                .Sortable()
                                .ToClientTemplate()

来源:https://stackoverflow.com/questions/27417604/kendo-grid-hierarchy-passing-id-from-master-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!