asp.net-mvc – 将List参数传递到ASP.NET MVC3中的自定义操作过滤器
发布时间:2020-09-02 04:55:36 所属栏目:asp.Net 来源:互联网
导读:我怎么能把List解析成自定义动作过滤器(比如输入参数)? public class CustomFilter : ActionFilterAttribute{ public ListMyEnumType InputParameter { get; set; } public override void OnActionExecuting(ActionExecutingC
我怎么能把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? (编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 所有请求获取HTTP错误401.2 – 未经授权的响
- asp.net-mvc – 使用Viewbag绑定DropdownlistFor
- asp.net – 获得“System.Web.Mvc.Html.MvcForm”一页
- asp.net-mvc – 使用NLog记录未处理的异常? ELMAH和NLog应
- asp.net – 多个用户控件和JavaScript
- ASP.NET MVC学习教程之Razor语法
- ASP.NET性能优化之局部缓存分析
- IIS ASP.NET WebApi在请求同一台服务器时死锁
- asp.net-mvc – 为什么在ASP.NET MVC中使用lambdas而不是反
- .net – RESTful WCF的裸最低配置
推荐文章
站长推荐
- asp.net-web-api – WebApi 2.1 PUT抛出错误415
- 模型 – 视图 – 控制器 – ASP.NET WebForms vs
- ASP.NET web.config中数据库连接字符串connectio
- asp.net – coldfusion和.net上的单点登录
- asp.net-core – 如何在ASP.NET 5中使用“旧”依
- asp.net-mvc-3 – 应该使用HTTP引用来验证还是令
- asp.net 删除项目文件/文件夹IIS重启,Session丢
- asp.net-mvc – MVC应用程序调试错误:viewstate
- .net – DNU发布 – 来自MSBuild的no-source
- global-variables – MVC 3 Razor _ViewStart中的
热点阅读