title: MVC3 Html.HiddenFor(Model => Model.Id) not passing back to Controller
body: <p>I have created a strongly typed MVC3 Razor view using the scaffolding code.</p>
  
  <p>The model is a POCO with a base type of <code>PersistentEntity</code> which defines a property called Created, Updated and Id.</p>
  
  <p>Id is an int, Created and Updated are DateTime.</p>
  
  <p>I am using <code>Html.HiddenFor</code> to create the hidden field on the view.</p>
  
  <pre><code>@Html.HiddenFor(model =&gt; model.Id)
  @Html.HiddenFor(model =&gt; model.Created)
  @Html.HiddenFor(model =&gt; model.Updated)
  </code></pre>
  
  <p>On the page, the hidden input is being rendered properly, with the Id being set in the value.</p>
  
  <pre><code>&lt;input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Id" name="Id" type="hidden" value="12"&gt;
  </code></pre>
  
  <p>However when the page is submitted to the controller <code>[HttpPost]Edit(Model model)</code> the Id property is always 0. Created and Updated are correctly populated with the values from the View.</p>
  
  <p><img src="https://i.stack.imgur.com/oIpSJ.png" alt="enter image description here"></p>
  
  <p>This should be 12 in the case of the example in this post. What is going wrong?</p>
  
  <hr>
  
  <p>I am aware that I can change the method signature to <code>[HttpPost]Edit(int personID, Person model)</code> as the personID is in the get string, however why does the model not get populated with the hidden field?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>The problem was that the setter on <code>PersistentEntity</code> was protected, ASP could not set the property, and swallowed it. Changing this to public has solved the problem.</p>
  
  <pre><code>public abstract class PersistentEntity
  {
      public virtual int Id { get; protected set; }
      public virtual DateTime Created { get; set; }
      public virtual DateTime Updated { get; set; }
  }
  </code></pre>