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

null hyperlink created by ClientTemplate

4 Answers 391 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Achilles
Top achievements
Rank 1
Achilles asked on 23 Jul 2013, 07:07 AM
Hi

I have a Kendo grid, where one of the columns is a text field, which represents an IP address. I have used a client template to create a hyperlink

c.Bound(o => o.AddrIP).Width(120)
    .ClientTemplate("<a href='http://#= AddrIP #' target='_blank'>#= AddrIP #</a> ")


This seems to work in principle.

But when a row has no IP address specified, I get a "null" as a string with a hyperlink to 'null'
Strangely, if I use the ClientTemplate format specified by the old MVC extenssions

c.Bound(o => o.AddrIP).Width(120)
    .ClientTemplate("<a href='http://#= AddrIP #' target='_blank'><#= AddrIP #></a> ")


I get a set of "<>" around the text (which is probably expected !!), but the "null" hyperlink problem disappears.

Any help to get the proper format would be appreciated

Regards

Achilles

4 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 23 Jul 2013, 11:14 AM
Hello Achilles,

I recommend you to use client template expressions to check the IP address value and construct the template content accordingly.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Achilles
Top achievements
Rank 1
answered on 25 Jul 2013, 11:18 AM
Hello Dimo,

I tried to use the different client templates according to the examples.
The basic template seems to work, but I'm still getting the 'null hyperlink' problem. I tried to use HTML encoding. But it's giving me some problems. 
I use MVC while the examples are in javascript. So I'm not sure if I could translate it right.

I'm attaching a sample project. I'd be grateful if you can have a quick look.

Regards

Achilles
0
Dimo
Telerik team
answered on 25 Jul 2013, 12:16 PM
Hello Achilles,

>> I recommend you to use client template expressions to check the IP address value and construct the template content accordingly.

What I meant is that you should use template expressions with an IF statement to check the IP address value and if it is null, do not render a hyperlink at all. Currently the hyperlink is still added in the template unconditionally.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Achilles
Top achievements
Rank 1
answered on 24 Sep 2013, 11:11 AM
I  finally found out how to use an IF statement within the ClientTemplate with the right advice from this post
http://www.kendoui.com/forums/kendo-ui-complete-for-asp-net-mvc/general-discussions/conditionals-embedded-in-client-templates.aspx

Thanks Dimiter.

Regards

Achilles
Tags
Grid
Asked by
Achilles
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Achilles
Top achievements
Rank 1
Share this question
or