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

Only show hyperlink when value is not null

6 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Web Support
Top achievements
Rank 1
Web Support asked on 26 May 2014, 11:31 AM
Hi,

I have the following code to show hyperlinks on my kendo grid, however it shows a link all the time, even when the value is null. Is there a way I can get the link to only show when the value (PDFString) is not null?

columns.Template(@<text>
                                                   @Html.ActionLink("View", "PayrollHistory", "ViewPDF")  
                                                 </text>)
                                                 .ClientTemplate("<a href='/PayrollHistory/ViewPDF/#= PDFString#' target='_blank'>View</a>")
                                                 .Title("View PDF");

Any suggestions welcome!

6 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 26 May 2014, 11:55 AM
Hi Phil,

Kendo UI Templates support JavaScript execution inside the template, as explained here:

http://docs.telerik.com/kendo-ui/getting-started/framework/templates/overview

In your case you can check whether the value is not null and only then render the link.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Web Support
Top achievements
Rank 1
answered on 26 May 2014, 01:03 PM
Thanks for the quick reply Kiril,

I've applied the following but it's still not working, it's difficult to know how it's working due to the weird syntax, could you give me any pointers - 

columns.Template(@<text>
                                                   @Html.ActionLink("View", "PayrollHistory", "ViewPDF")  
                                                 </text>)
                                                 .ClientTemplate("#if(PDFString != null){# <a href='/PayrollHistory/ViewPDF/#= PDFString#' target='_blank'>View</a> #}#")
                                                 .Title("View PDF");
0
Kiril Nikolov
Telerik team
answered on 27 May 2014, 06:57 AM
Hi Phil,

Your code looks OK. Could you please provide us with a runnable sample that we can play with and see what is happening?

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Web Support
Top achievements
Rank 1
answered on 27 May 2014, 09:38 AM
Hi,

The 2mb limit means I can't upload the solution. So I've attached the Index.cshtml and the HomeController.cs from a default project.

The grid appears on the index page and the controller provides to links, one with a value and one with a string.empty. You'll see that both links are displayed.

Let me know if you need more info.

Phil
0
Kiril Nikolov
Telerik team
answered on 28 May 2014, 07:13 AM
Hello Phil,

I have tested your template in another project and was not able to reproduce any errors. Do you see any errors in the browser console when you run the app? Can you strip some of the references in your project and attach it here, so we can test it, or maybe you can provide us with a live url? 

I am asking you all this, because I cannot see any particular reason for your code not to work. 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Web Support
Top achievements
Rank 1
answered on 28 May 2014, 07:41 AM
Hi,

There are no errors, what I need to happen is for only ONE link to be displayed, it currently displays both links!
Tags
Grid
Asked by
Web Support
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Web Support
Top achievements
Rank 1
Share this question
or