Url.Action in Column Template

4 posts, 0 answers
  1. Rob
    Rob avatar
    7 posts
    Member since:
    Apr 2018

    Posted 12 Dec 2019 Link to this post

    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

     

  2. Tsvetomir
    Admin
    Tsvetomir avatar
    661 posts

    Posted 16 Dec 2019 Link to this post

    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.
  3. Rob
    Rob avatar
    7 posts
    Member since:
    Apr 2018

    Posted 17 Dec 2019 in reply to Tsvetomir Link to this post

    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? 

  4. Tsvetomir
    Admin
    Tsvetomir avatar
    661 posts

    Posted 18 Dec 2019 Link to this post

    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.
Back to Top