码迷,mamicode.com
首页 > Web开发 > 详细

Asp.Net MVC HttpPost用法

时间:2018-02-02 20:10:10      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:cep   method   不能   new   用法   attr   public   否则   stat   

          一个Action只能用一个http 特性,例如:HttpPost 不能与HttpGet 或者多个HttpPost重复使用,否则会出错

          也可以用 [AcceptVerbs("put","get","post")]来表示一个Action可以共用多个请求。只要是包含了这个请求的,都可以调用此Action

          HttpPost 等可以和 AcceptVerbs 特性共用 

         

         比如:

             

[HttpPost]

[AcceptVerbs("put","get","post")]

public ActionResult Index()

{

return View();

}

         这样是可以的,但实际上他只是当Post提交的时候才进入此Action(或者此Action才能被调用)

         把[AcceptVerbs("put","get","post")]改成: [AcceptVerbs(HttpVerbs.Post)]与[HtppPost]共用也是可以的实际上效果一样

 

          自定义Http特性:

public class ZiDingYiAttribute : ActionMethodSelectorAttribute

{

private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Post);

public ZiDingYiAttribute()

{

}

public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)

{

return _innerAttribute.IsValidForRequest(controllerContext, methodInfo);

}

}

            使用:

 

                              

[ZiDingYi]

public ActionResult Index()

{

return View();

}

               

           这样就可以自定义一个Http特性

          

 

Asp.Net MVC HttpPost用法

标签:cep   method   不能   new   用法   attr   public   否则   stat   

原文地址:https://www.cnblogs.com/tangyanzhi1111/p/8406445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!