What is difference between a action with HTTPPOST or without it
public ActionResult Index()
{
return view();
}
[HTTPPOST]
public ActionResult Index(){
return vi开发者_Python百科ew();
}
what is the difference between both in ASP.NET MVC
If you don't define any attribute above the method then Action accepts all kind requests (GET, POST etc.)
If you define [HttpPost]
then only Post is accepted. In some cases it is very important to accept only certain kind of requests. W3.org has a good checklist when to use Get & Post.
Use GET if:
- The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
Use POST if:
- The interaction is more like an order, or
- The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service),
- or The user be held accountable for the results of the interaction.
Btw. In your example there is a problem with method signatures. Method signatures must be different even if you put attributes above them.
精彩评论