title: How do I make a textbox readonly only for a specific MVC Action?
body: <p>The title might be confusing, so here is my problem:
  I'd like in my View a readonly textbox only if my Action is for editing (something like EditLocation) and if my Action is intended for adding a new record (AddLocation), I'd like an editable textbox.</p>
  
  <p>My ff. code works, but I was wondering if there's a "cleaner" solution</p>
  
  <pre><code>@using (Html.BeginForm(Model.Location.Id == 0 ? "AddLocation" : "EditLocation", "Location"))
      {
          &lt;fieldset&gt;
              @Html.HiddenFor(x =&gt; x.Location.Id)
              @Html.HiddenFor(x =&gt; x.Location.CompanyGroupId)
              @Html.HiddenFor(x =&gt; x.CompanyGroup.Id)
              @Html.HiddenFor(x =&gt; x.CompanyGroup.Code)
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;&lt;span&gt;@ResourcesCommon.Location_Code&lt;/span&gt;&lt;/strong&gt;
                  @if (Model.Location.Id == 0)
                  {
                      @Html.TextBoxFor(x =&gt; x.Location.Code, new { @class = "form-control" })
                      @Html.ValidationMessageFor(x =&gt; x.Location.Code)
                  }
                  else
                  {
                      @Html.TextBoxFor(x =&gt; x.Location.Code, new { @class = "form-control", @readonly = "readonly" })
                      @Html.ValidationMessageFor(x =&gt; x.Location.Code)
                  }
  
              &lt;/div&gt; ...
  </code></pre>
  
  <p>Thanks and have a good week ahead!</p>