Dav*_*rák 6 asp.net-mvc asp.net-mvc-3
我如何解析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()
{
}
Run Code Online (Sandbox Code Playgroud)
我得错了错误
'InputParameter' is not a valid named attribute argument because it is not a valid attribute parameter type
Run Code Online (Sandbox Code Playgroud)
dev*_*tal 12
操作过滤器参数是操作过滤器的属性:
[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);
}
}
Run Code Online (Sandbox Code Playgroud)
属性参数类型仅限于此处描述的类型 - http://msdn.microsoft.com/en-us/library/aa664615%28v=vs.71%29.aspx
您可以通过属性构造函数传递集合,如此处所述 - 我可以使用数组或其他可变数量的参数初始化C#属性吗?
| 归档时间: |
|
| 查看次数: |
6878 次 |
| 最近记录: |