title: ASP MVC EditorTemplates for ComplexType
body: <p>I am a silent reader of stackoverflow and in almost all cases I find solution to my problems from others' posts from this website until yesterday when I got stuck on something and can't find a solution.</p>
  
  <p>Here is a little explanation on my app architecture:</p>
  
  <p>I have code-first entity model in a separate c# project and I am referencing it to my web project. I have following entities:</p>
  
  <pre><code>public class Employee
  {
      public Employee();
      public int EmployeeId {get;set;}
      public DateTime? DegreeCompleted{ get; set; }
      public virtual University University { get; set; }
  }
  public class University 
  {
      public University();
      public int UniversityId {get;set;}
      public short? TotalDegrees{ get; set; }
      public short? TempTotalDegrees{ get; set; }
  }
  </code></pre>
  
  <p>On view side, I have a Home view with Index.cshtml which is referring <code>Views/Shared/EditorTemplates/University.cshtml</code> as this:</p>
  
  <pre><code> @using (Ajax.BeginForm("SaveEmployee", new AjaxOptions
   { 
              HttpMethod="POST",
              OnBegin="disableSubmit",
              OnComplete = "enableSubmit",
              OnFailure = "enableSubmit",
              InsertionMode=InsertionMode.Replace
              }))
        {
        @Html.HiddenFor(model=&gt;model.EmployeeId)
        @Html.EditorFor(m =&gt; m.University, new { EmployeeId = Model.EmployeeId})
  </code></pre>
  
  <p>here is how University.cshtml looks:</p>
  
  <pre><code>@Html.HiddenFor(model=&gt;model.UniversityId)
  @Html.TextBoxFor(x =&gt; Model.TotalDegrees, new { @class="form-control", @min="5",@max="100",@type="number",@value=(Model.TotalDegrees.HasValue ? Model.TotalDegrees.Value : 5)})
  </code></pre>
  
  <p>on Index.cshtml, when I click on submit button it posts back the Employee object to server but </p>
  
  <p>Employee.University.TotalDegrees is null, even though user fills in the value</p>
  
  <p>If I remove <code>@Html.HiddenFor(model=&gt;model.UniversityId)</code> from University.cshtml, <code>Employee.University</code> comes as null on post. </p>
  
  <p>I have tried to use <code>@Html.EditorFor(model=&gt;model.TotalDegrees)</code> and <code>@Html.TextBoxFor(model=&gt;model.TotalDegrees)</code> but none of them seems to work</p>
  
  <p>If I moved everyfrom from University.cshtml to main View, everything seems to work fine. </p>
  
  <p>Any help or suggestion appreciated.</p>