Controller
[ActionName("Index")]
[HttpPost]
public ActionResult IndexPost(string button, int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
string buttonClicked = Request.Form["SubmitButton"];
if(buttonClicked == "Accept")
{
CurrentApplication currentApplication = db.CurrentApplications.Find(id);
currentApplication.AppStatus = "APPROVED";
db.SaveChanges();
}
else if(buttonClicked == "Decline")
{
CurrentApplication currentApplication = db.CurrentApplications.Find(id);
currentApplication.AppStatus = "UNAPPROVED";
db.SaveChanges();
}
//Save Record and Redirect
return RedirectToAction("Index");
}
Index View
<button type="submit" name="SubmitButton" value="Approve" class="btn btn-sm btn-success">Approve</button>
<button type="submit" name="SubmitButton" value="Unapprove" class="btn btn-sm btn-danger">Unapprove</button>
In my Index view, i have a table where there are rows of data i can "Approve" or "Disapprove" using 2 buttons. I tried using these http://www.scriptscoop.net/t/b7bd27aee268/c-asp-net-mvc-two-different-buttons-in-form-submit.html and ASP.NET MVC two different buttons in form submit. I want the status value to change to Approve or Disapprove when the user clicks the corresponding button. But I'm not sure why it isn't working as I tried to code it similarly to the Edit view.