title: How to get data from two occurences of same partial view using encapsulting class model
body: <p>I have an autocompleter as a partial view which I would like to use twice in the same page. There are three models involved</p>
  
  <pre><code>public partial class CustomParent
  {
  
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Int64 CustomParentId { get; set; }
  
      public Geoname ParentGeoname { get; set; }
      public Geoname ChildGeoname { get; set; }
  
      public CustomParent()
      {
          ParentGeoname = new Geoname();
          ChildGeoname = new Geoname();
      }
  }
  public partial class Geoname
  {
      [Required]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Int64 GeonameId { get; set; }
      public string Name { get; set; }
  }
  public partial class GeonameWithFilter
  {
      public GeonameWithFilter()
      {
          FilterString = "";
      }
      public Geoname Geoname { get; set; }
      public String FilterString { get; set; }
  }
  </code></pre>
  
  <p>I have a controller set up</p>
  
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = "CustomParentId,ParentGeoname,ChildGeoname")] CustomParent customParent)
      {...}
  </code></pre>
  
  <p>I set up the two Html partials on my create view initially only using the customparent and geoname models and it worked fine setting the values in of the parent and child geonames as expected. I now require additional parameters to be passed to the partial view so I created an encapsulating class (GeonameWithFilter). I made changes to my partial view and to my two html.partials on the view page which now look like this :</p>
  
  <pre><code>            @Html.Partial("_GeonameAutocomplete",new GeonameWithFilter(){Geoname = Model.ParentGeoname,FilterString="'featurecodes':'CUPA'"},
                  new ViewDataDictionary()
                  {
                      TemplateInfo = new TemplateInfo() { HtmlFieldPrefix = "ParentGeoname" }
                  })
              @Html.Partial("_GeonameAutocomplete", new GeonameWithFilter() { Geoname = Model.ChildGeoname, FilterString = "'featurecodes':'ADM1,ADM2,ADM3,ADM4'" },
                  new ViewDataDictionary()
                  {
                      TemplateInfo = new TemplateInfo() { HtmlFieldPrefix = "ChildGeoname" }
                  })
  </code></pre>
  
  <p>The problem is that the customparent.parentGeoname and customparent.childGeoname are not now getting returned to my controller.  I'm guessing this is because the partial view's model is not the same class as my page models parentGeoname and childGeoname but cannot work out or find any examples of how to handle such a circumstance if indeed it is possible. </p>