How can I pass value of PGId by click checkbox and get value of checkbox to update value.
my view display a list got from method "Index"
@model PagedList.IPagedList<PG.Admin.Models.PGProfiles.PGProfileViewModel>
@using (Html.BeginForm("UpdateStatus", "PGProfile", FormMethod.Post))
{
for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Html.DisplayFor(m => m[i].PGId)
@Html.HiddenFor(m => m[i].PGId)
</td>
<td>
@Html.CheckBoxFor(m => m[i].Status)
<button type="submit" class="btn btn-primary btn-sm">update</button>
</td>
</tr>
}
<script>
// how can I write a ajax event of checkbox to pass value of PGId to controller
</script
my controller nested method Index to get all data and method Post UpdateStatus
// bind all data and work fine
public ActionResult Index()
{
var pgProfiles = _pgProfileService.GetAllPGProfiles().ToListViewModel();
return View(pgProfiles)
}
//update status by pgID
[HttpPost]
public ActionResult UpdateStatus(IEnumerable<PGProfileViewModel> model)
{
foreach (var item in model)
{
var pgProfiles = _pgProfileService.GetPGProfileById(item.PGId);
pgProfiles = item.ToEntity(pgProfiles);
pgProfiles.PGId = item.PGId;
_pgProfileService.UpdatePGProfile(pgProfiles);
}
return RedirectToAction("Index");
}