Blake Rivell
Blake Rivell

Reputation: 13875

Inline Razor conditional statement that will only display html attribute and value if condition is met

Is there anyway I can change this inline razor conditional statement so that the class attribute isn't always output to the html unless the class is actually being added. I don't want my html to have class="" in it.

<div id="wrapper" class="@(isMobile ? "mobileView" : "")">

Upvotes: 0

Views: 2092

Answers (1)

Fran
Fran

Reputation: 6520

What about

<div id="wrapper" @(isMobile ? "class=\"mobileView\"" : "")>

Upvotes: 2

Related Questions