Conditional HTML Attributes using Razor MVC3

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…

<input type="text" id="@strElementID" class="@strCSSClass" />

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

SSSHHH…don’t tell. 🙂

Leave a Comment