Conditional HTML Attributes using Razor

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 write things like this:

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

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

Further Reading

  • Jon Galloway – ASP.NET MVC 4 Beta Released!
  • Conditional Attributes in Razor View Engine and ASP.NET MVC 4

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)