title: Razor forms with lists
body: <p>New to MVC and just struggling with retrieving my form data from a List&lt;>. In my controller, I am able to get my Name value (recipe name) correctly but cannot get the Ingredient Name value, always coming back as NULL?</p>
  
  <p>Below are some code snippets from my project.</p>
  
  <p>MODEL</p>
  
  <pre><code>public class Recipe
  {
  
      [Required]
      public string Name { get; set; }
      public List&lt;Ingredient&gt; Ingredients { get; set; }
  
      public Recipe()
      {
          Ingredients = new List&lt;Ingredient&gt;()
          {
              new Ingredient()
          };
  
      }
  }
  
  public class Ingredient
  {
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>VIEW</p>
  
  <pre><code>@using (Html.BeginForm("CreateEdit", "Recipe"))
      {
          @Html.ValidationSummary()
          &lt;div class="form-group"&gt;
              @Html.LabelFor(x =&gt; x.Name, "Name")
              @Html.TextBoxFor(x =&gt; x.Name, new { @class = "form-control" })
              @Html.ValidationMessageFor(x =&gt; x.Name)
          &lt;/div&gt;
  
          &lt;h2&gt;Ingredient(s)&lt;/h2&gt;
          &lt;div class="form-group"&gt;
              @Html.LabelFor(x =&gt; x.Ingredients.FirstOrDefault().Name, "Name")
              @Html.TextBoxFor(x =&gt; x.Ingredients.FirstOrDefault().Name, new { @class = "form-control" })
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;input class="btn btn-primary" type="submit" text="submit" /&gt;
          &lt;/div&gt;
      }
  </code></pre>
  
  <p>CONTROLLER</p>
  
  <pre><code>[HttpPost]
  public ActionResult CreateEdit(Recipe recipe)
  {           
     var recipeName = recipe.Name // &lt;--- Works
     var ingredientName = recipe.Ingredients.FirstOrDefault().Name; //&lt;--- NULL value
  
     return View(recipe);
  }
  </code></pre>