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

[Solved] Databound Expression in nested DetailView issue

1 Answer 19 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 16 Jan 2013, 01:49 PM
I have a Master/Detail Client mode grid. The detail also has a detailTemplate to render some Html containing various action links.

I am using Databound expressions to supply the variable parts of the actionlink from the model. Some of the expression replacements are not working and it is not clear why. Examples of the same type of replacement are working in the master/detail grids but fail in the lowest DetailTemplate. 

This is a simplified version of the code:

@(Html.Telerik().Grid<AppraiseeListItemModel>()
           .Name("Appraisees")
           .DataKeys(keys => keys.Add(o => o.EmployeeId).RouteKey("id"))
                 .DataBinding(dataBinding => dataBinding.Ajax()
                             .Select("GetAppraiseesForManager", "Home"))
           .Columns(columns =>
           {
               columns.Bound(c => c.Name).Title("Appraisee").Filterable(true).HeaderHtmlAttributes(new { @class = "FilterOnlyOn_Contains" });
           })
           .Filterable()
           .Sortable(sorting => sorting.Enabled(true))
           .TableHtmlAttributes(new { style = "table-layout:fixed;" })
           .Pageable(paging => paging.Enabled(true))
 
           .DetailView(details => details.ClientTemplate(
                 Html.Telerik().Grid<AppraisalListItemModel>()
                     .Name("Appraisals_<#= EmployeeId #>")
                     .DataKeys(keys => keys.Add(q => q.AppraisalId))
                     .DataBinding(dataBinding => dataBinding.Ajax()
                         .Select("GetAppraisalsForEmployee", "Home", new { employeeId = "<#= EmployeeId #>" }))
                     .Columns(columns =>
                     {
                         columns.Bound(o => o.AppraiserName).Title("Appraiser(s)").Width(100);
                         columns.Bound(o => o.Year).Title("Year").Width(5);                       
                      
                         columns.Bound(o => o.AppraisalId).Width(200).Title("Full")
                         
                                .ClientTemplate(
                                    "<# if (CanViewFullAppraisal) {#> "
                                    + Html.ActionLink("<#= FullAppraisalText #>", "<#= FullAppraisalAction #>", "Home", new { id = "<#= FullAppraisalActionId #>", year = Model.Year, isManager = true }, new { @class = "t-button" }).ToHtmlString()
                                    + "<# } #>");                                             
                     })
                     .Pageable()
                     .DetailView(d => d.ClientTemplate(
                         "<fieldset style='border: thin #ccc; padding: 6px;'>" +
                             
                             Html.ActionLink("<#= DeferAppraisalText #>", "DeferAppraisal", "Home", new { id = "<#= ChangeAppraisalStatusId #>", deferReasonId = "dummyDeferReasonId" }, new { @id = "defer-link", @style = "<#= DeferAppraisalStyle #>", @class = "defer-appraisal-action t-button" }).ToHtmlString() +
                           
                         "</fieldset>"))
                     .ToHtmlString())))

.ClientTemplate(
                                    "<# if (CanViewFullAppraisal) {#> "
                                    + Html.ActionLink("<#= FullAppraisalText #>", "<#= FullAppraisalAction #>", "Home", new { id = "<#= FullAppraisalActionId #>", year = Model.Year, isManager = true }, new { @class = "t-button" }).ToHtmlString()
                                    + "<# } #>");    

The above code in the nested Detail grid works. id = "<#= FullAppraisalActionId #>" the replacement for this works.

This does not work.

Html.ActionLink("<#= DeferAppraisalText #>", "DeferAppraisal", "Home", new { id = "<#= ChangeAppraisalStatusId #>", deferReasonId = "dummyDeferReasonId" }, new { @id = "defer-link", @style = "<#= DeferAppraisalStyle #>", @class = "defer-appraisal-action t-button" }).ToHtmlString()

This gets replaced ok: <#= DeferAppraisalText #>
but this renders without replacement (i.e. you get the expression code not its value replacement) new { id = "<#= ChangeAppraisalStatusId #>",

I have updated to the latest version of Telerik MVC just in case but that didnt resolve the issue.

John



1 Answer, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 17 Jan 2013, 10:17 AM
I managed to fix this by using the solution in this post.

http://www.telerik.com/community/forums/aspnet-mvc/grid/can-t-get-action-link-working-with-data-bound-parameter-and-client-template.aspx

I am not sure why it fixes it but it does.

Basically you wrap the Html.ActionLink in a Server.UrlDecode().
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or