title: ASP.net MVC5 - For loop posts single item but not the collection
body: <p>I am creating a new recipe entry form and I am finding two interesting problems:</p>
  
  <ol>
  <li>The Ingredient does not post to the recipe collection, and</li>
  <li>The Form will only post a single ingredient and sends null when I have the parameter set to a collection.</li>
  </ol>
  
  <p>Ideally, I'd like the ingredient collection to be under the recipe item, but I'll settle for just getting the ingredient collection to write to the parameter.</p>
  
  <p>Here are the two models (Generated by entity framework):</p>
  
  <p><strong>Recipe:</strong></p>
  
  <pre><code>    public int recipeId { get; set; }
  
      [Required]
      [StringLength(255)]
      [DisplayName("Name")]
      public string name { get; set; }
  
      [DisplayName("Category")]
      public int? mealCategoryId { get; set; }
  
      [DisplayName("Preperation Time")]
      public int? prepTime { get; set; }
  
      [DisplayName("Cook Time")]
      public int? cookTime { get; set; }
  
      [DisplayName("Stand Time")]
      public int? standTime { get; set; }
  
      [DisplayName("Serving Size")]
      public int? servingSize { get; set; }
  
      [DisplayName("Status")]
      public int recipeStatusId { get; set; }
  
      [DisplayName("Description")]
      [UIHint("Multiline")]
      public string description { get; set; }
  
      public virtual ICollection&lt;Direction&gt; Directions { get; set; }
  
      public virtual ICollection&lt;Image&gt; Images { get; set; }
  
      public virtual ICollection&lt;Ingredient&gt; Ingredients { get; set; }
  
      public virtual MealCategory MealCategory { get; set; }
  
      public virtual ICollection&lt;Nutrition&gt; Nutritions { get; set; }
  
      public virtual ICollection&lt;Rating&gt; Ratings { get; set; }
  
      public virtual RecipeStatus RecipeStatus { get; set; }
  }
  </code></pre>
  
  <p><strong>Ingredient:</strong></p>
  
  <pre><code>public partial class Ingredient
      {
          public int ingredientId { get; set; }
  
          public int? recipeId { get; set; }
  
          public int? subCategoryId { get; set; }
  
          public int measurementId { get; set; }
  
          public int amount { get; set; }
  
          public virtual Recipe Recipe { get; set; }
  
          public virtual SubCategory SubCategory { get; set; }
  
          public virtual Measurement Measurement { get; set; }
  
      }
  </code></pre>
  
  <p><strong>View Code:</strong></p>
  
  <pre><code>   &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Ingredients&lt;/h4&gt;
          &lt;hr /&gt;
          &lt;table class="table IngredientList"&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.LabelFor(model =&gt; model.Recipe.Ingredients)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.LabelFor(model =&gt; model.SelectedMeasurementId)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.Label("Amount")
                  &lt;/th&gt;
              &lt;/tr&gt;
  
              @for (int i = 0; i &lt; Model.Recipe.Ingredients.Count; i++)
              {
                  &lt;tr&gt;
                      &lt;td&gt;
                          @Html.DropDownListFor(m =&gt; Model.Recipe.Ingredients.ElementAt(i).ingredientId, Model.SubIngredients, new { @class = "form-control input-block-level" })
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DropDownListFor(m =&gt; Model.Recipe.Ingredients.ElementAt(i).measurementId, Model.Measurements, new { @class = "form-control input-block-level" })
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.TextBoxFor(m =&gt; Model.Recipe.Ingredients.ElementAt(i).amount, new { @class = "form-control input-block-level" })
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
  
          &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>   [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(Recipe recipe, int SelectedCategoryId, List&lt;Ingredient&gt; Ingredients)
  
      {
          recipe.mealCategoryId = SelectedCategoryId;
          recipe.recipeStatusId = 1;
  
          if (ModelState.IsValid)
          {
              dbContext.Entry(recipe).State = EntityState.Added;
              dbContext.SaveChanges();
              return RedirectToAction("Details", new {id = recipe.recipeId});
          }
  
          return View(recipe);
      }
  </code></pre>
  
  <p>So, if I have the parameter set to List Ingredients then null is returned. If I have it set to Ingredient Ingredients then I get only the first of four ingredients. (I have the model set to create 4 ingredient records upon loading.)</p>
  
  <p>My question is: How do I get it to pass the collection of ingredients?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have confirmed that the request is sending all 4 of the ingredients over. It seems to be a problem with the binding. </p>