I want to delete a object from my database using ASP.NET MVC. I have connected to the database with Entity Framework. I have made this code for my controller named Delete.
// DELETE-POST [HttpPost] [ValidateAntiForgeryToken] public IActionResult Delete(int? id) { var obj = _db.Project.Find(id); if(obj == null) { return NotFound(); } _db.Project.Remove(obj); _db.SaveChanges(); return RedirectToAction("Index"); } Then I created a button with a link to my controller
<a asp-action="Delete" class="btn btn-danger btn-lg text-white w-30">Delete</a> I had expect that my object should disappear. But I get an issue when I press the button. It only returns a blank site with a message that the site does not work.
Does anyone have any ideas why?