csharp 允许json动作过滤器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 允许json动作过滤器相关的知识,希望对你有一定的参考价值。

public class AllowJsonGetAttribute : ActionFilterAttribute
{
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        var jsonResult = filterContext.Result as JsonResult;

        if (jsonResult == null)
            throw new ArgumentException("Action does not return a JsonResult, attribute AllowJsonGet is not allowed");

        jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;            

        base.OnResultExecuting(filterContext);
    }
}

以上是关于csharp 允许json动作过滤器的主要内容,如果未能解决你的问题,请参考以下文章

csharp 用于测试WebApi动作过滤器的助手类

csharp ASP.net MVC3的程序化GZip动作过滤器

csharp 一个过滤器属性,允许您将ASP.NET MVC视图下载为Word文档

不允许过滤

csharp 动作重定向

csharp 动作重定向