Is there a way to create a column template using Url.Action to create a similar function to the foreign key ability with MVC Grid? Ultimately I want the treelist to display the "DataText" field not the "DataValue" field.
columns.Add().Field(e => e.TimeFrameId).Template("@Url.Action("GetTimeFrame","Template", new {timeFrameId = #:TimeFrameId#})");
Thanks
5 Answers, 1 is accepted
Hi Rob,
The evaluation of the Action is not synchronized with the evaluation of the templates of the Kendo UI TreeList. Therefore, at the time of the creation of the anchor tag, the template would not return an accurate value. What I can recommend is that you append the query parameters manually. Here is an example:
columns.Add().Field(e => e.LastName).Width(160).Template("<a href=" + @Url.Action("GetTimeFrame", "Template") + "?timeFrameId=#=FirstName#>#=FirstName#</a>");
In case further assistance is needed, let me know.
Best regards,
Tsvetomir
Progress Telerik

Hey Tsvetomir,
I am unfamilar with the template structure you used in the beginning with the query '?timeFrameId=' . I didnt see a question mark used in the template overview page, is there documentation explaining that in more detail?
Hi Rob,
The approach that was provided in my previous response is not directly related to the Kendo UI Grid or its templates. This approach is a tailored approach for your specific scenario. Since the Url.Action is evaluated at a different time compared to the Kendo template. The Url.Action returns a string representing the URL path of the browser. On top of that, I added the value of the field as a custom query parameter.
Is there something unclear or should I provide any additional information? Is the provided approach applicable in your case?
Looking forward to your reply.
Best regards,
Tsvetomir
Progress Telerik

Just following up on this one - is there really no way to create this using Url.Action to support route parameters?
For example:
"<
a
href=\"" + Url.Action("Edit", "Map", new {
Area
=
"Sites"
,
SiteId
=
"#=SiteId#"
,
id
=
"#=MapId#"
}) + "\"
class
=
'btn btn-primary btn-sm mr-2'
>View</
a
>"
I have explicitly defined route parameters applied around all parts of my application and would like to honour these for consistency - from your reply above is there really no way to achieve this? Or am I forced to use querystring parameters meaning this section will not be consistent with other application screens.
Hi Paul,
It is correct that there is no way to call the Url.Action with a variable from JavaScript. This is due to the fact, the Url.Action is server-side code and the other is client-side code. Even though it might look as if it is possible for pass parameters between the two - it is not possible. And this is valid for any cases beyond the grid's ClientTemplate.
The only scenario that you could undertake is to concatenate manually the values with the generated URL.
Kind regards,
Tsvetomir
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.