title: MVC5 Add Item to List
body: <p>Given a Model of : </p>
  
  <pre><code>public class Receipt: BaseEntity
  {
      [Required(AllowEmptyStrings = false,ErrorMessage = "Please Select A Store")]
      public Store  Store { get; set; }
      public List&lt;Item&gt; Items { get; set; }
      public Item NewItem { get; private set; }
      [Required(AllowEmptyStrings = false,ErrorMessage = "ReceiptModel.EntryDate is required")]
      public DateTime EntryDate { get; set; }
      public Guid EntryOwner { get; set; }
      public string Name { get; set; }
  
      public double ReceiptTotal()
      {
          return Items.Sum(item =&gt; item.ItemPrice);
      }
      public Receipt()
      {
          Items = new List&lt;Item&gt;();
          EntryOwner = Guid.Empty;
          EntryDate = DateTime.Now;
          Store = new Store();
          NewItem = new Item();
       }       
  }
  </code></pre>
  
  <p>And a Controller : </p>
  
  <pre><code>public class ReceiptController : Controller
  {
      //
      // GET: /Receipt/
  
      public ActionResult Index()
      {
          Receipt receipt = new Receipt();
          return View(receipt);
      }
  
      [HttpPost]
      public ActionResult AddItem(Receipt receipt)
      {
          receipt.Items.Add(receipt.NewItem);
          if (ModelState.IsValid)
          {
              return View("Index", receipt);
          }
          return View("Index", receipt);
      }
  </code></pre>
  
  <p>And a View: <strong>Updated View - Removed all partial pages and combined into a single page</strong></p>
  
  <pre><code>&lt;form class="form-horizontal" method="POST" action="@Url.Action("AddItem","Receipt")"&gt;
  &lt;div class="jumbotron"&gt;
      &lt;div id="main" class="panel panel-primary"&gt;
  
          &lt;div class="panel-heading"&gt; &lt;h1 class="panel-title"&gt;Receipt Builder&lt;/h1&gt;&lt;/div&gt;
          &lt;div class="panel-body"&gt;
  
              &lt;fieldset&gt;
                  @Html.LabelFor(model =&gt; model.Name)
                  @Html.EditorFor(model =&gt; model.Name)
  
                  @Html.LabelFor(model =&gt; model.Store.Name)
                  @Html.EditorFor(model =&gt; model.Store.Name)
  
                  @Html.LabelFor(model =&gt; model.EntryDate)
                  @Html.EditorFor(model =&gt; model.EntryDate)
              &lt;/fieldset&gt;
  
          &lt;/div&gt;
  
  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;table class="table table-bordered table-condensed table-hover table-responsive table-striped"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;#&lt;/label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;Item&lt;/label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;Unit&lt;/label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;Quantity&lt;/label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;UnitPrice&lt;/label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;Category&lt;/label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;label class="control-label"&gt;Total&lt;/label&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  
                  &lt;td&gt;
                      &lt;button class="btn-sm btn-danger" style="border-radius: 50%; background-color: red;" name="Submit" id="Submit" type="submit"&gt;+&lt;/button&gt;
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.Name)
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.UnitType)
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.Quantity)
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.UnitPrice)
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.Category.Name)&lt;br/&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.Category.IsTaxable)
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      @Html.EditorFor(model =&gt; model.NewItem.ItemPrice)
                  &lt;/td&gt;
  
  
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach (var item in Model.Items)
          {
              &lt;tr&gt;
                  &lt;td&gt;
                      @Model.Items.ToList().IndexOf(item) + 1
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.LabelFor(titem =&gt; item.Name)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.LabelFor(titem =&gt; item.UnitType)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.LabelFor(titem =&gt; item.Quantity)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.LabelFor(titem =&gt; item.UnitPrice)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.LabelFor(titem =&gt; item.Category.Name)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.LabelFor(titem =&gt; item.ItemPrice)
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  
      &lt;tfoot&gt;&lt;/tfoot&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p></p>