Conditional HTML Attributes using Razor MVC3

后端 未结 3 1738
温柔的废话
温柔的废话 2020-11-27 03:13

The variable strCSSClass often has a value but sometimes is empty.

I do not want to include an empty class=\"\" in this input element\'s HTML, which means if strCSS

3条回答
  •  盖世英雄少女心
    2020-11-27 03:25

    You didn't hear it from me, the PM for Razor, but in Razor 2 (Web Pages 2 and MVC 4) we'll have conditional attributes built into Razor(as of MVC 4 RC tested successfully), so you can just say things like this...

    
    

    If strCSSClass is null then the class attribute won't render at all.

    SSSHHH...don't tell. :)

提交回复
热议问题