ASP.NET MVC razor: conditional attribute in HTML [duplicate]

MVC has conditional attributes built in. For example:

<div @{if (myClass != null) { <text>class="@myClass"</text> } }>Content</div>
<div class="@myClass">Content</div>

If @myClass is null, it just won’t use the attribute at all.

I know that may not quite solve your current issue, but it is noteworthy!

See also: John Galloway’s blog post on ASP.NET MVC 4 Beta > Conditional attribute rendering

Leave a Comment

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