title: MVC EditorFor Optionally ReadOnly
body: <p>Yesterday, after extensive testing, I got the following to optionally apply the readonly attribute to a control based on the value of <code>ViewBag.CanEdit</code>;</p>
  
  <pre><code>@Html.EditorFor(m =&gt; m.Location, new { htmlAttributes = new { @class = "form-control", @readonly = (ViewBag.CanEdit == true ? Html.Raw("") : Html.Raw("readonly")) } })
  </code></pre>
  
  <p>Based on the success of this testing I implemented and tested it in several parts of my project.  Today I started on a new section of the code and commenced implementing the same code only to have it consistently fail - every control is <code>readonly</code>.</p>
  
  <p>When I inspected the controls they either have <code>readonly</code> or <code>readonly=readonly</code> as the attribute?  I then went back to the code I refactored yesterday to find the same problem; every control is now <code>readonly</code> regardless of the value of <code>ViewBag.CanEdit</code>?</p>
  
  <p>Can anyone explain why this would have worked yesterday but fails today?</p>