Hi, Happy New Year All. I am having this issues with updating selected input textbox in a table rows.
Here is my Code
My View Page
- @using (Html.BeginForm("Update_Record", "Customer", FormMethod.Post))
- {
-
-
- <table id="zero_config" class="table table-striped table-bordered display">
-
- <thead>
- <tr>
- <th>
-
- <div class="icheck-primary">
- <input type="checkbox" id="Check_All" />
-
-
- <label for="ContractId">
-
- </label>
- </div>
- </th>
- <th>
- Employee Name
- </th>
-
-
- <th>Update Salary</th>
- <th>
- Date
- </th>
-
-
- </tr>
- </thead>
- <tbody>
- @for (int i = 0; i < Model.Count(); i++)
- {
- <tr>
- <td>
-
-
- <div class="icheck-primary">
-
-
- <input type="checkbox" id="ContractId" name="contId" value="@Model[i].ContractId" />
-
-
- <label for="ContractId">
-
- </label>
- </div>
- </td>
- <td>
- @Html.DisplayFor(modeli => Model[i].Customer.Name)
- </td>
-
-
- <td>
-
- <input type="number" step="0.01" class="form-control" id="@Model[i].ContractId"
- value="" name="TxtPayout" max="" />
-
- </td>
-
-
- <td>
-
- <input type="date" id="@Model[i].ContractId" value="@DateTime.Now.ToString("yyyy-MM-dd")" name="TxtDatePaid" class="form-control" />
- </td>
-
-
-
- </tr>
- }
- </tbody>
-
-
- </table>
- <input type="submit" value="Update Record" class="btn btn-primary" />
- }
My Controller [HttpPost]
- public ActionResult Update_Record(System.Web.Mvc.FormCollection form)
- {
-
-
- string[] contid = form.GetValues("contId");
- decimal total = 0;
- int cnt = 0;
- if(contid != null)
- {
- string[] payout = form.GetValues("TxtPayout");
- string[] datepaid = form.GetValues("TxtDatePaid");
- for(int i = 0; i < contid.Length; i++)
- {
- decimal salary = Convert.ToDecimal(payout[i]);
- DateTime dt = Convert.ToDateTime(datepaid[i]);
- total += salary;
- cnt++;
- }
- TempData["Message"] = string.Format("Successfully Updated with {0} record(s) affected Total Payout: {1}", cnt, total);
-
- }
-
- getContract();
- return View(ViewBag.gct);
- }
If i check the entire row and update, it works. but if i check any of the rows, it throws up error. What i want to achieve it to get the input values of only the rows i check instead of getting the entire input values of the input text boxes. Kindly Assist me with.. Thanks for your valued time..