title: Multiple instances of partial views and model binding on same page with MVC
body: <p>I have a partial twice on a view.  Partial doesnt use a loop and has basic validation.</p>
  
  <p>Here is the <strong>partial</strong> view code:</p>
  
  <pre><code> &lt;div class="col-md-4"&gt;
                      @Html.LabelFor(model =&gt; model.ZipCode, new { @class = "control-label " })
                      @Html.TextBoxFor(model =&gt; model.ZipCode, new { @class = "form-control ",  tabindex = "4" })
                      @Html.ValidationMessageFor(model =&gt; model.ZipCode)
                  &lt;/div&gt;
  </code></pre>
  
  <p>Here is my <strong>main view</strong> calling it twice:</p>
  
  <pre><code>&lt;div id="homeaddress"&gt;
                                  @if (Model == null)
                                  {
                                  @Html.Partial("~/Views/AddrPartial.cshtml", new Address())
                              }
                              else
                              {
                                  @Html.Partial("~/Views/AddrPartial.cshtml", Model.HomeAddress)
                              }
                          &lt;/div&gt;
  
  &lt;div id="mailingaddress"&gt;
                                  @if (Model == null)
                                  {
                                      @Html.Partial("~/Views/AddrPartial.cshtml", new Address())
                                  }
                                  else
                                  {
                                      @Html.Partial("~/Views/AddrPartial.cshtml", Model.MailingAddress)
                                  }
                              &lt;/div&gt;
  </code></pre>
  
  <p>Then only the "homeadrress" div validation works... here's how my  model is setup:</p>
  
  <pre><code>    public class Information
     {
      public Address HomeAddress { get; set; }
      public Address MailingAddress { get; set; }
      }
  </code></pre>
  
  <p>Then  have a separate Address class...</p>
  
  <pre><code>public class Address
  {
          [Display(Name = "Address")]
          public string Addr1 { get; set; }
          [Display(Name = "Address 2")]
          public string Addr2 { get; set; }
          [Display(Name = "Zip Code")]
          [RegularExpression(@"^\d{5}(-\d{4})?|^$", ErrorMessage = "Invalid Zip Code")]
          public string ZipCode { get; set; }
  
  }
  </code></pre>
  
  <p>The html generated shows the problem... the mailingaddress html doesnt have the regex necessary to check validation.. </p>
  
  <pre><code>&lt;input class="form-control " data-val="true" data-val-regex="Invalid Zip Code" data-val-regex-pattern="^\d{5}(-\d{4})?|^$" id="ZipCode_home" name="ZipCode_home"  tabindex="4" type="text" value="12345"&gt;
  &lt;span class="field-validation-valid" data-valmsg-for="ZipCode_home" data-valmsg-replace="true"&gt;&lt;/span&gt;
  
  &lt;input class="form-control " id="ZipCode_mailing" name="ZipCode_mailing"  tabindex="4" type="text" value="54321"&gt;
  &lt;span class="field-validation-valid" data-valmsg-for="ZipCode_mailing" data-valmsg-replace="true"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>after reviewing this code my question is why is this happening and how can i fix this.  Thanks in advance I can answer questions and provide more code if need be.</p>