altTemplate with MVC helpers

4 posts, 0 answers
  1. Phil
    Phil avatar
    18 posts
    Member since:
    Nov 2012

    Posted 06 Mar 2013 Link to this post

    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.
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 07 Mar 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Rene
    Rene avatar
    65 posts
    Member since:
    Nov 2010

    Posted 20 Mar 2013 Link to this post

    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?
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 20 Mar 2013 Link to this post

    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!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready