zoukankan      html  css  js  c++  java
  • Asp.Net MVC HttpPost用法

              一个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特性

              

  • 相关阅读:
    linux日志守护进程 syslog
    ORM(一)
    ajax
    python bbs项目代码分析
    jquery基础
    PHP根据概率产生随机数
    用PHP删除文件操作unlink
    实时显示剩余可以输入的文字数
    mysql分表方法实现
    php 输出昨天,今天,明天是星期几的方法
  • 原文地址:https://www.cnblogs.com/tangyanzhi1111/p/8406445.html
Copyright © 2011-2022 走看看