title: ASP.NET MVC: How do other people apply conditional CSS classes?
body: <p>Say I have two CSS styles called <code>january</code> and <code>tuesday</code>.  I want to apply them to some text fields in my view depending on whether or not it's January, and Tuesday.</p>
  
  <p><strong>Option A: Do the logic in the controller, and put the styles in the ViewData.</strong></p>
  
  <p>In the controller:</p>
  
  <pre><code>if( month == Month.January) 
    ViewBag.UserNameCssStyles = "january";
  if( today == Day.Tuesday )
    ViewBag.UserNameCssStyles += " tuesday";
  </code></pre>
  
  <p>And in the view: </p>
  
  <pre><code>@Html.TextBoxFor(model =&gt; model.UserName, new { @class = ViewBag.UserNameCssStyles }
  </code></pre>
  
  <p><strong>Option B: Do the logic in the controller and assign the styles in the view?</strong></p>
  
  <p>In the controller: </p>
  
  <pre><code>ViewBag.IsJanuary = (month == Month.January);
  ViewBag.IsTuesday = (today == Day.Tuesday);
  </code></pre>
  
  <p>And in the view:</p>
  
  <pre><code>@if (ViewBag.IsJanuary &amp;&amp; !ViewBag.IsTuesday) 
  {
    @Html.TextBoxFor(model =&gt; model.UserName, new { @class = "january" })
  }
  else if (!ViewBag.IsJanuary &amp;&amp; ViewBag.IsTuesday)
  {
    @Html.TextBoxFor(model =&gt; model.UserName, new { @class = "tuesday" })
  }
  else if(ViewBag.IsJanuary &amp;&amp; ViewBag.IsTuesday)
  {
    @Html.TextBoxFor(model =&gt; model.UserName, new { @class = "january tuesday" })
  }
  else
  {
    @Html.TextBoxFor(model =&gt; model.UserName)
  }
  </code></pre>
  
  <p>Neither way seems right to me.  The first option has the controller concerning itself with display, and also kind of locks up the styles so someone working on the view can't change them and, say, add a third class.  But the second option seems pretty logic-heavy for being just the "dumb" view.</p>
  
  <p>How do other people normally do this?</p>