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

Nested Grid Hyperlink using Parent Id instead of Child Id

2 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arthur
Top achievements
Rank 1
Arthur asked on 04 Mar 2014, 05:20 PM
Hi,

When I create a hyperlink in the nested grid, it is using the parent unique id over the child unique id.  This results in an incorrect URL.

Below is the code for the template kendo grid.

<script id="Load_PCSO" type="text/kendo-templ">
    <h3>Power Cost Savings</h3>
 
    @(Html.Kendo().Grid<PowerCostSaving>()
          .Name("PCSO_#=SiteId#")
          .Columns(columns =>
              {
                  columns.Bound(p => p.Id).Width("50px").ClientTemplate(Html.ActionLink("#=Id#", "PowerCostSavingEdit", "Account", new {siteId = "#=SiteId#", powerCostSavingId = "#=Id#"}, null).ToString());
                  columns.Bound(p => p.Id);
                  columns.Bound(p => p.Type).Width("150px");
                  columns.Bound(p => p.FollowUpDate).Width("100px").HtmlAttributes(new {style = "text-align: center"});
                  columns.Bound(p => p.Lead).Width("150px");
                  columns.Bound(p => p.Savings).Width("100px").HtmlAttributes(new {style = "text-align: right"});
                  columns.Bound(p => p.Status).Width("100px");
                  columns.Bound(p => p.DateOfStatus).Width("100px").HtmlAttributes(new {style = "text-align: center"});
              })
          .DataSource(dataSource => dataSource.Ajax()
                                              .PageSize(20)
                                              .Read(read => read.Action("PSCO_Load", "AccountReview", new { siteId = "#=SiteId#"}))
                                              .ServerOperation(true))
          .HtmlAttributes(new { style = "width: 800px;" })
          .ToClientTemplate()
          )
 
</script>

If you look at the attached image, you will noticed that the id in the hyperlink in the first column differs from the id in the second column.  I would like the hyperlink to use the id in the second column.

Thank You,
Arthur

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 05 Mar 2014, 06:44 AM
Hello Arthur,

You should escape the nested template expressions, like this:
columns.Bound(p => p.Id)
 .Width("50px")
 .ClientTemplate(Html.ActionLink("\\#=Id\\#", "PowerCostSavingEdit", "Account",
  new {siteId = "#=SiteId#", powerCostSavingId = "\\#=Id\\#"}, null)
 .ToString());

This ways the `Id` field from nested grid will be evaluated instead of the parent.


Regards,
Nikolay Rusev
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

0
Arthur
Top achievements
Rank 1
answered on 05 Mar 2014, 04:11 PM
That works!  Thank You.
Tags
Grid
Asked by
Arthur
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Arthur
Top achievements
Rank 1
Share this question
or