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

Url.Action in Column Template

5 Answers 2463 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 12 Dec 2019, 10:00 PM

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

Sort by
0
Tsvetomir
Telerik team
answered on 16 Dec 2019, 03:51 PM

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

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
0
Rob
Top achievements
Rank 1
answered on 17 Dec 2019, 01:54 PM

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? 

0
Tsvetomir
Telerik team
answered on 18 Dec 2019, 02:45 PM

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

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
0
Paul
Top achievements
Rank 1
Veteran
answered on 12 Feb 2021, 04:00 PM

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.

 

0
Tsvetomir
Telerik team
answered on 15 Feb 2021, 05:06 PM

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/.

Tags
TreeList
Asked by
Rob
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Rob
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Veteran
Share this question
or