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

Getting a 'null' value in client template of Kendo ListView

3 Answers 958 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Amorphous2010
Top achievements
Rank 1
Amorphous2010 asked on 20 Aug 2013, 07:44 PM
I have a simple Kendo ListView with an applied client template. If the data in the row item to which the template is applied happens to be null, then the text 'null' appears by default. How can I change this behavior without having to do ${ ShipToName == null ? '' : ShipToName } every time? I am using a template that has to display numerous bound data items, and having to check for null on each and every one of them is tedious and results in code bloat. Even more importantly (and possibly a second question), I need to be able to evaluate the data value from within one of the Razor MVC HTML wrappers, and am constantly getting an 'Invalid template' exception. Please help!

Example #1:

<script type="text/x-kendo-tmpl" id="editTemplate">
 //This is always 'null' by default
 #=ShipToName#
 //This correctly displays null values as empty string
 ${ ShipToName == null ? '' : ShipToName }
</script>

Example #2:

<script type="text/x-kendo-tmpl" id="editTemplate">
//This works, but always displays 'null' as the value in the textbox
@Html.TextBox("ShipToName", "#=ShipToName#")
//This causes an 'Invalid template' error
@Html.TextBox("ShipToName", "#if (ShipToName != null) {# #=''# #} else {# #=ShipToName# #}#")
</script>


3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 22 Aug 2013, 09:23 AM
Hello Shawn,

I am afraid that there is not other way - you need to check if the value is null, however you can use an external function ti save some space.

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-use-a-javascript-function-in-a-column-client-template?

Regarding the second question:

@Html.TextBox("ProductName", "#if (ProductName != null) {# #=''# #} else {# #=ProductName# #}#")

The second parameter (the value) becomes encoded which ends as an invalid template. Use regular input element instead.

Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Matt
Top achievements
Rank 1
Veteran
answered on 11 Aug 2014, 12:06 AM
You probably mean: ProductName == null
Then it shows the product name if it is not null.

@Html.TextBox("ProductName", "#if (ProductName == null) {# #=''# #} else {# #=ProductName# #}#")
0
bobthecoder
Top achievements
Rank 1
answered on 06 Jul 2015, 08:44 PM
you have ProductName != null above. I think you mean ProductName == null
Tags
ListView
Asked by
Amorphous2010
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Matt
Top achievements
Rank 1
Veteran
bobthecoder
Top achievements
Rank 1
Share this question
or