Nested Grid Hyperlink using Parent Id instead of Child Id

3 posts, 1 answers
  1. Arthur
    Arthur avatar
    2 posts
    Member since:
    Sep 2013

    Posted 04 Mar 2014 Link to this post

    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. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 05 Mar 2014 Link to this post

    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!

  3. Arthur
    Arthur avatar
    2 posts
    Member since:
    Sep 2013

    Posted 05 Mar 2014 in reply to Nikolay Rusev Link to this post

    That works!  Thank You.
Back to Top