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 Salaryth>
- <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; // to get the total salaries
- int cnt = 0; //Count Affected Rows
- 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; //Convert.ToDecimal(payout[i]);
- cnt++;
- }
- TempData["Message"] = string.Format("Successfully Updated with {0} record(s) affected Total Payout: {1}", cnt, total);
- }
- getContract();
- return View(ViewBag.gct);
- }
Sachin SinghPosted Jan 2, 2021, 11:20 AM