I am trying to delete an entity from Index view page like this
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<button type="submit" value="delete" formaction="/Issue/Delete">Delete</button>
}
on this button click I want my DeleteConfirmed Action inside controller to happen (not go to another delete page).
Inside controller
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Issue issue = _db.Issues.Find(id);
_db.Issues.Remove(issue);
_db.SaveChanges();
return RedirectToAction("Index");
}
Right now it throws an error
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DeleteConfirmed(Int32)' in 'DiagnosisApp.Controllers.IssueController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Can anyone point out what is the correct approach to achieve this?