My Action link looks like so:
<%= Html.ActionLink("Delete Message", "DeleteMessage", new { messageId=item.MESSAGEID })%>
And my Action in my controller looks like so:
[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult DeleteMessage(int messageId)
{
Message message = context.Messages.FirstOrDefault(m => m.MESSAGEID.Equals(messageId));
if (message != null)
{
context.Messages.DeleteOnSubmit(message);
context.SubmitChanges();
}
return View();
}
But for some reason, the item in my model still does not get deleted. Where have I gone wrong?
ActionLinkproduces anaelement with a link which is accessed with standardGETrequest. Your action, however, explicitly specifies that it expectsDELETEmethod, hence it never actually gets invoked.Moreover, no “destructive” actions should be performed with
GETrequests. See this on implementing “delete” link.