یا اسم remove رو بکنید Delete و بالاش فقط [HttpPost] بذارید یا اینکه اگر می خواهید همین اسم (remove) باشه بالاش علاوه بر [HttpPost] این رو هم باید بذارید: [ActionName("Delete")]
قطعه کد کامل:
[HttpGet]
public ActionResult Delete(int id=0)
{
var st = context.Students.Find(id);
if (st == null)
{
return HttpNotFound();
}
return View(st);
}
[ActionName("Delete")]
[HttpPost]
public ActionResult remove(int id)
{
var st = context.Students.Find(id);
if (st == null)
{
return HttpNotFound();
}
context.Students.Remove(st);
context.SaveChanges();
return RedirectToAction("index");
}