title: Edit and update rows in dynamic table in Asp.net mvc4 razor view
body: <p>I am new to asp.net MVC. I have a dynamic table in my project. Adding dynamic rows in table is achieved with the help of following link</p>
  
  <p><a href="https://stackoverflow.com/questions/29433666/adding-and-deleting-rows-in-dynamic-table-in-asp-net-mvc-razor-view">Adding and deleting rows in dynamic table in Asp.net mvc razor view</a></p>
  
  <p>I need to edit and update the dynamic table.
  I have tried following code </p>
  
  <p>My sample model</p>
  
  <pre><code>public class Gift
  {
      public string Name { get; set; }
      public double Price { get; set; }   
  }
  
  public class GiftViewModel
  {
      public string Age { get; set; }
      public DateTime TheDate { get; set; }
      public IEnumerable&lt;Gift&gt; Gifts { get; set; }
  }
  </code></pre>
  
  <p>My sample Controller</p>
  
  <pre><code>public class HomeController : Controller
  {
      [HttpGet]
      public ActionResult Index()
      {
          return View();
      }
  
      [HttpPost]
      public ActionResult Index(GiftViewModel model)
      {               
          // do work here 
          return RedirectToAction("Index");
      }
  
      public ViewResult AddNew()
      {
          return View("_TimeSheetView");
      }
  }
  </code></pre>
  
  <p>My sample Partial View</p>
  
  <pre><code>@model HelloWorldMvcApp.Gift
  @using (Html.BeginCollectionItem("giftList"))
  {
      &lt;div&gt; 
          &lt;span class="drop_medium"&gt;
              @Html.TextBoxFor(m =&gt; m.Name)
          &lt;/span&gt;
          &lt;span class = "drop_medium"&gt;
               @Html.TextBoxFor(m =&gt; m.Price)
          &lt;/span&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>My sample main view</p>
  
  <pre><code>@model HelloWorldMvcApp.GiftViewModel
  @using (Html.BeginForm())
  {
      @Html.TextBoxFor(m =&gt; m.Age)
      @foreach (var data in Model.Gifts)
      {
          { Html.RenderPartial("_TimeSheetView", data); }
      }
      @Html.ActionLink("Add another", "AddNew", null, new { id="addItem" })
      &lt;input type="submit" value="Save"/&gt;
  }
  
  &lt;script type="text/javascript"&gt;
      $("#addItem").click(function () {
          $.ajax({
              url: this.href,
              cache: false,
              success: function (html) { $("#dynamic").append(html); }
          });
          return false;
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>When I click 'Add Another' button a row is added to the table. After editing the values in the table When I click submit button I receive nothing in the controller. The IEnumerable Gifts variable is null. How to take the table values to the controller. Please help me to fix this is issue. Thanks in advance</p>