asp.net-mvc – 将List参数传递到ASP.NET MVC3中的自定义操作过滤器

我怎么能把List解析成自定义动作过滤器(比如输入参数)?
public class CustomFilter : ActionFilterattribute
{

    public List<MyEnumType> InputParameter { get; set; }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {         
        base.OnActionExecuting(filterContext);
    }
}

[CustomFilter(InputParameter = new List<MyEnumType>() { MyEnumType.Type } )]
public SomeActionInController()
{
}

我得错了错误

'InputParameter' is not a valid named attribute argument because it is not a valid attribute parameter type

解决方法

操作过滤器参数是操作过滤器的属性
[CustomFilter(InputParameter=10)]
public SomeActionInController()
{
}

public class CustomFilter : ActionFilterattribute
{
  public int InputParameter { get; set; }

  public override void OnActionExecuting(ActionExecutingContext filterContext)
  {
    // access this.InputParameter

    base.OnActionExecuting(filterContext);
  }
}

属性参数类型仅限于此处描述的类型 – http://msdn.microsoft.com/en-us/library/aa664615%28v=vs.71%29.aspx

您可以通过属性构造函数传递集合,如此处所述 – Can I initialize a C# attribute with an array or other variable number of arguments?

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....