title: MVC3 Conditionally disable Html.TextBoxFor()
body: <p>I have a C# .Net web app. In that app I need to conditionally disable <code>Html.TextBoxFor</code> controls (also <code>Html.DropDownListFor</code> controls) based on who is logged into the system.  I tried using</p>
  
  <pre><code> @Html.TextBoxFor(model =&gt; model.ProposalName, new { @ViewBag.IsDisabled })
  </code></pre>
  
  <p>Where <code>@ViewBag.IsDisabled</code> is set to either <em>String.Empty</em> or <em>"disabled"</em> in the Controller. However, this renders as <code>IsDisabled='disabled'</code> or <code>IsDisabled=""</code> so the control is not disabled. When I tried</p>
  
  <pre><code>@Html.TextBoxFor(model =&gt; model.ProposalName, new { @ViewBag.Disabled })
  </code></pre>
  
  <p>The control was always disabled even if <code>ViewBag.Disabled</code> contained no text.  How can I conditionally disable the <code>Html.TextBoxFor()</code> controls?</p>