Conditional HTML Properties - How to realize?

6 posts, 1 answers
  1. Malcolm
    Malcolm avatar
    29 posts
    Member since:
    Oct 2011

    Posted 18 Jun 2014 Link to this post

    Hello Dear Telerik Team!

    I want to realize a scenario where Html-Attributes are conditionally applied to cells. In a ClientTemplate it would look like
    " #if(BooleanProperty) { <p style=\"MyStyle: MyValue\">#= ValueProperty #</p> } else { <p>#=ValueProperty#</p> } "
    My Questions now:
    1. Is this possible without using a client template?
    2. How exactly must the syntax look like?

    I hope you can help me...

    brgds
    Malcolm
  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 18 Jun 2014 Link to this post

    Hello Malcolm,


    Using a client template with conditional logic inside is the correct way to go in the current case.

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Will
    Will avatar
    4 posts
    Member since:
    Sep 2013

    Posted 10 Mar 2015 in reply to Dimiter Madjarov Link to this post

    Hi Dimiter,

    I have a ForeignKey column that I would rather not create a ClientTemplate for, but would like to conditionally set an html attribute

    static: HtmlAttribute( new{ @class = "specialClass" } );

    desired pseudo-code...
    conditional: HtmlAttribute( "#if (IsSpecial) {# new{ @class = 'specialClass' } #}#");

    Is there any way to accomplish conditional HtmlAttributes without using a client template?

    Thanks,
    Will

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 11 Mar 2015 Link to this post

    Hello Will,

    HtmlAttributes is a server method and is rendered on the server side. This is why a client template cannot be used inside, because the data is read on the client side via Ajax.

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 16 Jun 2015 in reply to Dimiter Madjarov Link to this post

    Why couldn't you allow us to pass a lambda to .HtmlAttributes() that allowed us to specify the attributes based on the value of one of the model properties?
  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 17 Jun 2015 Link to this post

    Hello Curt,

    The reason is described in my previous post. HtmlAttributes is a server method and is rendered on the server side, while the data is bound later on the client side via Ajax.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready