Passing a list of <Enum> parameters to a custom action filter in ASP.NET MVC3

how can I parse the list into a custom action filter (e.g. input parameters)?

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() { } 

I got an error error

 'InputParameter' is not a valid named attribute argument because it is not a valid attribute parameter type 
+6
source share
1 answer

Action filter options are the properties of an action filter:

 [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); } } 

Attribute parameter types are limited to the types described here - http://msdn.microsoft.com/en-us/library/aa664615%28v=vs.71%29.aspx

You can pass the collection through the attribute constructor as described here - Is it possible to initialize a C # attribute using an array or another variable number of arguments?

+11
source

Source: https://habr.com/ru/post/892655/


All Articles