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

Escaping hash / pound / sharp inside link in ClientTemplate

9 Answers 331 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Julia
Top achievements
Rank 1
Julia asked on 04 Mar 2015, 04:34 PM
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
                          

9 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 06 Mar 2015, 01:25 PM
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.

 
0
Julia
Top achievements
Rank 1
answered on 06 Mar 2015, 10:03 PM
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!
0
Alexander Popov
Telerik team
answered on 10 Mar 2015, 12:15 PM
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.

 
0
Julia
Top achievements
Rank 1
answered on 10 Mar 2015, 06:48 PM
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.
0
Julia
Top achievements
Rank 1
answered on 10 Mar 2015, 07:07 PM
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
0
Julia
Top achievements
Rank 1
answered on 10 Mar 2015, 07:42 PM
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.
0
Julia
Top achievements
Rank 1
answered on 11 Mar 2015, 09:04 PM
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;
});
                           
0
Alexander Popov
Telerik team
answered on 12 Mar 2015, 11:57 AM
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.

 
0
Julia
Top achievements
Rank 1
answered on 12 Mar 2015, 01:57 PM
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. 
Tags
Grid
Asked by
Julia
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Julia
Top achievements
Rank 1
Share this question
or