title: Aspnet core MVC Partial view for sub class data
body: <p>I have a model that looks like this: </p>
  
  <pre><code>public class Product
  {
      [Key]
      public int Id { get; set; }
      [Required]
      public string CatalogId { get; set; }
      [Required]
      public string Name { get; set; }
      [Required]
      public string Description { get; set; }
      [Required]
      [EnumDataType(typeof(Category))]
      public Category Category { get; set; }
  
      public IEnumerable&lt;Features&gt; Features { get; set; }
  }
  </code></pre>
  
  <p>And I have a view that allows me to create a new product using this model.</p>
  
  <p>For the Features, I'm trying to create a partial view that will allow me to add new <code>Features</code> to List, attach it to the product and submit to the <code>AddNewProduct()</code> method in my controller.</p>
  
  <p>Here's my <code>AddNewProduct</code> view:</p>
  
  <pre><code>@model Product
  
  &lt;div class="card card-admin-main"&gt;
  &lt;div class="card card-header-admin"&gt;
      &lt;nav class="navbar navbar-expand-lg navbar-light bg-light" style="background-color: grey !important;"&gt;
      &lt;a class="navbar-brand" href="/admin"&gt;Admin&lt;/a&gt;
      &lt;button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"&gt;
          &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
      &lt;/button&gt;
  
      &lt;div class="collapse navbar-collapse" id="navbarSupportedContent"&gt;
          &lt;ul class="navbar-nav mr-auto"&gt;
          &lt;li class="nav-item active"&gt;
              &lt;a class="nav-link" href="/admin"&gt;Overview &lt;span class="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;
          &lt;/li&gt;
          &lt;li class="nav-item"&gt;
              &lt;a class="nav-link" href="/admin/products"&gt;Products&lt;/a&gt;
          &lt;/li&gt;
  
      &lt;/div&gt;
      &lt;/nav&gt;
  &lt;/div&gt;
  
  
  &lt;form asp-action="AddNewProduct"&gt;
      &lt;br&gt;
          &lt;div class="col-md-12"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;a asp-for="CatalogId" &gt;Catalog ID&lt;/a&gt;
                      &lt;input asp-for="CatalogId" class="form-control"&gt;
                      &lt;a asp-for="Name" &gt;Name&lt;/a&gt;
                      &lt;input asp-for="Name" class="form-control"&gt;
  
                      &lt;a asp-for="Category" &gt;Category&lt;/a&gt;
                      &lt;select asp-for="Category" asp-items="Html.GetEnumSelectList&lt;Category&gt;()" class="form-control"&gt;
                          &lt;option selected="selected" value=""&gt;Please select&lt;/option&gt;
                      &lt;/select&gt;    
  
                  &lt;/div&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;a asp-for="Description" &gt;Description&lt;/a&gt;
                      &lt;textarea asp-for="Description" class="form-control" rows="7"&gt;&lt;/textarea&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      @if(Model != null)
                      {
                          foreach(var feature in Model.Features)
                          {
                              @feature.FeatureTitle
                          }
                      }
                      @await Html.PartialAsync("_AddNewFeaturePartial", new Features())
  
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;br&gt;
                      &lt;button type="submit" class="btn btn-primary"&gt;Save&lt;/button&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>Heres my <code>_AddNewFeaturePartial</code></p>
  
  <pre><code>@model Features
  
  
  &lt;form asp-action="AddFeature" asp-controller="Admin" method="POST"&gt;
      &lt;a asp-for="FeatureTitle"&gt;Feature&lt;/a&gt;
      &lt;input asp-for="FeatureTitle" class="form-control"&gt;
      &lt;a asp-for="FeatureDescription"&gt;Description&lt;/a&gt;
      &lt;input asp-for="FeatureDescription" class="form-control"&gt;
      &lt;button type="submit" class="form-control"&gt;Add Feature&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here are my controller methods:</p>
  
  <pre><code>    public IActionResult AddNewProduct(Product newProduct)
      {
          if(newProduct.CatalogId != null)
          {
  
          }
          return View();
      }
      [HttpPost]
      public IActionResult AddFeature(int id, string FeatureTitle, string FeatureDescription)
      {
  
          return RedirectToAction("AddNewProduct");
      }
  </code></pre>
  
  <p>If I add a new feature to the form and click <code>Add new Feature</code> It never hits <code>public IActionResult AddFeature(int id, string FeatureTitle, string FeatureDescription</code></p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>