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

altTemplate with MVC helpers

3 Answers 75 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 06 Mar 2013, 04:30 PM
I can't figure out how to specify an altTemplate with the MVC Helper.  Is this possible?  I tried adding the altTemplate later in jQuery code and it seems that I have to re-specify all values from the MVC Helper as well.

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 07 Mar 2013, 03:48 PM
Hi Phil,

The altTemplate cannot be currently specified with the MVC wrappers. As a workaround I would suggest you the following approach - Define a global boolean variable, check it in your template script and select the appropriate template to render according to it's value.
E.g.

<script>
    var templateCheck = true;
</script>
<script type="text/x-kendo-tmpl" id="template">
    #if(templateCheck){#
       //regular Template
    # } else { #
       //alternative Template
    # } #
    #templateCheck = !templateCheck;#
</script>

 

Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rene
Top achievements
Rank 1
answered on 20 Mar 2013, 01:13 PM
How would you handle 3 different "templates" - the one to be used depending on the value in a model object ? (in data)

something like:

if( oModel.CarType == 'TYPE_1' )
  use this template code/strings
else if ( oModel.CarType == 'TYPE_2' )
  use this template / code/strings
else if ( oModel.CarType == 'TYPE_3')
  use this template code/strings

Basically - depending on the item being displayed's CarType - the proper template is used to display that item on the listview item?
0
Dimiter Madjarov
Telerik team
answered on 20 Mar 2013, 01:58 PM
Hi Phil,


To achieve this you could use a similar approach. You could reference the model property directly. 
E.g.
<script type="text/x-kendo-tmpl" id="template">
    #if(CarType == 'TYPE_1'){#
        //first template
    # } else if (CarType == 'TYPE_2') { #
        //second template
    # } else { #
        //third template
    # } #
</script>

Additional information about Kendo templates could be found in the Demos and in the Documentation.

 

Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView
Asked by
Phil
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Rene
Top achievements
Rank 1
Share this question
or