title: Incorrect model property value rendered in partial view
body: <p>I have a strongly-typed partial view whose model contains a property with the same name as the parent page's view model.  For some reason the rendering engine is rendering the parent view model value, not the expected value (well, the value I expect at least!)</p>
  
  <p>Parent page view model extract:</p>
  
  <pre><code>public class ParentPageViewModel
  {
      public int Id { get; set; } // problem property
      ...
      public IEnumerable&lt;ChildViewModel&gt; Children { get; set; }
  }
  </code></pre>
  
  <p>Child page view model extract:</p>
  
  <pre><code>public class ChildViewModel
  {
      public int Id { get; set; } // problem property
      ...
  }
  </code></pre>
  
  <p>Parent page extract (Razor):</p>
  
  <pre><code>@model ParentPageViewModel
  ...
  @foreach (var item in Model.Children)
  {
      @Html.Partial("MyPartialView", item)
  }
  ...
  </code></pre>
  
  <p>Partial view extract:</p>
  
  <pre><code>@model ChildViewModel
  ...
  &lt;form ...&gt;
      @Html.HiddenFor(m =&gt; m.Id) // problem here - get ParentPageViewModel.ID not ChildViewModel.Id
  &lt;/form&gt;
  ...
  </code></pre>
  
  <p>So basically in my rendered output, my hidden field has the value of the parent view model element, NOT the value passed to the partial view.  It's definitely being caused by the name, as changing the name of @ChildViewModel.Id@ to something like @ChildViewModel.ChildId@ makes it work as expected.  Interestingly, when inspecting the view model values in the debugger I do see the correct values; it's only the rendered output that's wrong.</p>
  
  <p>Is there a way round this or 'correct' way of doing what I'm trying to do (I'm rendering mini forms in a table for ajax validation/posting of updates to table rows)</p>
  
  <p>Thanks,</p>
  
  <p>Tim</p>