This is a migrated thread and some comments may be shown as answers.

How to create a custom child grid column with ActionLinks containing IDs of the child model

2 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mehmet
Top achievements
Rank 1
Mehmet asked on 23 May 2013, 04:48 PM
Hi,

how do i add a custom column to a child grid containing a Action Link with the ID of the current child row entity?

here is a example of the hierarchical grid:
@(Html.Kendo().Grid<MyParentGridModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.Id).Groupable(false).Width(50);
        columns.Bound(p => p.Name);
        columns.Bound(p => p.ShortDescription);
        columns.Bound(p => p.LinkText);
    })
    .Sortable()
    .Pageable()
    .Scrollable(scr=>scr.Height(500))
    .ClientDetailTemplateId("template")
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("ParentModel_Read", "ControllerName"))
    )   
)
 
<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<ChildGridModel>()
        .Name("Grid_#=Id#")
        .Columns(columns =>
        {
            columns.Bound(o => o.PageNumber).Width(50);
            columns.Bound(o => o.ChapterTitle).Width(150);
            columns.Bound(o => o.BodyContent);
            columns.Template(@<text>
                            @Html.ActionLink("edit", "ControllerAction", "ControllerName", new { id = @item.Id }, new {@class = "k-button" })
                            </text>)
            .ClientTemplate(@Html.ActionLink("edit", "ControllerAction", "ControllerName", new { ID = "#=Id#" }, new { @class = "k-button" }).ToHtmlString());
 
             
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(10)
            .Read(read => read.Action("ChildModel_Read", "ControllerName", new { parentModelId = "#=Id#" }))
        )
        .Pageable()
        .Sortable()
        .ToClientTemplate()
    )
</script>
The Question is: How can the Id of the ChildModelEntity be resolved and passed into the ActionLinkMethod?  "#=Id#" returns the Id of the parent model.

Thanks in advance for answers!

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 24 May 2013, 12:53 PM
Hello Mehmet,

You must escape the `#` from the child Grid client template:

columns.ClientTemplate(@Html.ActionLink("edit", "ControllerAction", "ControllerName", new { ID = "\\#=Id\\#" }, new { @class = "k-button" }).ToHtmlString());

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mehmet
Top achievements
Rank 1
answered on 27 May 2013, 02:56 PM
Hi Nikolay,

thank you for your reply! This works fine!

Tags
Grid
Asked by
Mehmet
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Mehmet
Top achievements
Rank 1
Share this question
or