[HttpPost]是一个在ASP.Net MVC中装饰控制器或控制器动作的属性.如果类型为"POST",您将使用它仅允许请求输入此操作方法.
通常看起来像这样:
[HttpPost]
public ActionResult MyControllerAction()
{
// only can get here if httprequest was a "POST"
}
Run Code Online (Sandbox Code Playgroud)
一个[WebMethod]属性用于装饰旧学校.asmx页面上的方法,该页面通常用于制作Web服务.将该[WebMethod]属性附加到Public方法表示您希望该方法作为XML Web服务的一部分公开.
通常在.asmx页面上看起来像这样:
public class Service1 : System.Web.Services.WebService
{
[WebMethod] // exposes XML Web Service Method
public DataSet IAmAWebServiceMethod()
{
//implementation code
}
}
Run Code Online (Sandbox Code Playgroud)
它们没有可比性,并且完全不同的操作.一个处理Web应用程序的"POST"请求,而另一个处理XML Web Service方法.