Reputation: 3236
http://msdn.microsoft.com/en-us/library/system.web.mvc.httpdeleteattribute.aspx Represents an attribute that is used to restrict an action method so that the method handles only HTTP DELETE requests.
But what the heck does that mean for example Mvc
@Html.ActionLink("delete", new {id= model.PrimaryKey})//
Is that a Delete Request? how would the browser differentiate between
@Html.ActionLink("gridDisplay", new {id= model.PrimaryKey})//
controller
[HttpDelete] //what is this how does it know?
public action result delete()
{
delete();//web service deletes something just go with me here
}
public action result gridDisplay()
{
return view()
}
Upvotes: 3
Views: 6615
Reputation: 141688
Delete is an HTTP verb, just like GET, PUT, and POST. This attribute restricts the action method to only handle HTTP delete requests.
It's typical to see this as part of a RESTful web service. This makes it entirely clear that the HTTP request will perform some type of deletion.
You can't just link to an action that will perform an HTTP delete. A link in a browser will usually issue a GET. I would expect you to get a 404 from clicking that link.
Upvotes: 6
Reputation: 13594
First of all, none of the View Code you showed is a delete and won't be treated as an HTTP DELETE verb.
The controller code you shown signifies to an action method decorated with HttpDelete, which means that this code will be executed on Delete request with the same name as the action name.
How does it know it ?
It doesn't. Your View code will have a similar link like HTTP.Post, namely HTTP.Delete link which will direct to this action
Upvotes: 0