Escaping hash / pound / sharp inside link in ClientTemplate

10 posts, 0 answers
  1. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 04 Mar 2015 Link to this post

    I searched the forum for my issue but the suggestions here (escaping the # with \\ or \\\\) did not work.

      columns.Bound(Function(l) l.Path).Title("File Path").ClientTemplate("<a href=""#= Path.replace('ROOT\\', '\\\\test123.com\\test\\WAV\\Compliance\\') #"" target=""_blank"">#= Path.replace('ROOT\\', '\\\\cmutual.com\\fsroot\\WAV\\Compliance\\') #</a>")

    If my Path contains a "#", the link gets cut off after that symbol (and does not open the linked file, obviously). 

    Interestingly, when the link is clicked, for a second the whole correct path is in the address bar (with the "#" and everything after it), but after a second, it gets replaced with the cut off path.

    Thanks,
    Julia
                              
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1442 posts

    Posted 06 Mar 2015 Link to this post

    Hi Julia,

    I tried reproducing this, but everything worked as expected. Could you please check this screencast and let me know if I am doing something differently?

    Regards,
    Alexander Popov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 06 Mar 2015 in reply to Alexander Popov Link to this post

    Hi Alexander,

    My company blocks screencast.com. I will try to look at your example from home but is there another way for you to share your implementation with me? That would save me quite a bit of time. Thank you!
  4. Alexander Popov
    Admin
    Alexander Popov avatar
    1442 posts

    Posted 10 Mar 2015 Link to this post

    Hi Julia,

    Please find the video attached.

    Regards,
    Alexander Popov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 10 Mar 2015 in reply to Alexander Popov Link to this post

    Hi Alexander,

    Thank you for the quick reply with the video. Since you already gave me the right syntax in C#'s Razor (and I spent 1/2 hour trying to convert it to VB.NET's Razor), would it be too much to ask for the VB.NET's version of the answer? Thanks a lot.

    The syntax in your answer gives me this error at runtime:
    Comma, ')', or a valid expression continuation expected.

    I currently have:
    columns.Bound(Function(l) l.Path).Title("LAN/SPN Site Path").ClientTemplate("<a href=\"#= Path # \" target=\"_blank\">#= Path #</a>")

    Thanks again.
  6. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 10 Mar 2015 in reply to Julia Link to this post

    Alexander,

    After an additional 10 minutes of searching I found how to fix my Razor view problem:

    When I have an additional double quote, everything, including the link not cutting off at the hash symbol, works:
    columns.Bound(Function(l) l.Path).Title("LAN/SPN Site Path").ClientTemplate("<a href=\""#= Path # \"">#= Path #</a>")

    Thanks a lot for your help,

    Julia
  7. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 10 Mar 2015 in reply to Julia Link to this post

    Well, I am not sure what happened but I am now having trouble with the syntax:
    columns.Bound(Function(l) l.Path).Title("LAN/SPN Site Path").ClientTemplate("<a href=""#= Path # "">#= Path #</a>")

    The link cuts off at the first space now.

    So I am still looking for help with translating your original answer to VB.NET Razor. Thanks.
  8. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 11 Mar 2015 in reply to Julia Link to this post

    So after spending a day trying to escape a # in ClientTemplate, I gave up. Instead I am using Javascript.

    If anyone wants to see this, here's my implementation:

    columns.Bound(Function(l) l.Path).Title("LAN/SPN Site Path").HtmlAttributes(New With { .class = "LANPath", .id= "LANPath" })

    $(document).on("click", "#LANPath", function (e) {

    var grid = $("#FormLinkGrid").data("kendoGrid");
    var model = grid.dataItem($(e.target).closest("tr"));
    var path = model.Path;
    var url = encodeURIComponent(path);
    var url2 = url.replace(/#/g, '%23');

    window.location.href = 'file:///' + url2;
    });
                               
  9. Alexander Popov
    Admin
    Alexander Popov avatar
    1442 posts

    Posted 12 Mar 2015 Link to this post

    Hello Julia,

    The template's syntax is the same regardless of whether Razor or ASPX is used, as it is part of the Kendo UI templating system and is evaluated on the client-side.

    Regards,
    Alexander Popov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Julia
    Julia avatar
    7 posts
    Member since:
    May 2014

    Posted 12 Mar 2015 in reply to Alexander Popov Link to this post

    Alexander,

    I am using Razor but it's VB.NET's. There are differences between C# and VB.NET Razor, just do a Google search. In any case, The syntax you provided:

    columns.Bound(Function(l) l.Path).Title("LAN/SPN Site Path").ClientTemplate("<a href=\"#= Path # \">#=Path #</a>")


    Results in a run time error:

    \Instance\Details.vbhtml(516): error BC32017: Comma, ')', or a valid expression continuation expected.

    Thanks. 
Back to Top