asp.net-mvc – 用于枚举的IRouteConstraint
发布时间:2020-12-15 19:52:22 所属栏目:asp.Net 来源:网络整理
导读:我想创建一个IRouteConstraint,它根据枚举的可能值过滤值. 我试图为自己谷歌,但这并没有导致任何结果. 有任何想法吗? 解决方法 见 this 基本上,你需要 private Type enumType; public EnumConstraint(Type enumType) { this.enumType = enumType; } public
我想创建一个IRouteConstraint,它根据枚举的可能值过滤值.
我试图为自己谷歌,但这并没有导致任何结果. 有任何想法吗? 解决方法
见
this
基本上,你需要 private Type enumType; public EnumConstraint(Type enumType) { this.enumType = enumType; } public bool Match(HttpContextBase httpContext,Route route,string parameterName,RouteValueDictionary values,RouteDirection routeDirection) { // You can also try Enum.IsDefined,but docs say nothing as to // is it case sensitive or not. return Enum.GetNames(enumType).Any(s => s.ToLowerInvariant() == values[parameterName].ToString()); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 使用Visual Studio 2013 Preview调试ASP.NE
- asp.net – jquery将一个onclick事件添加到href链接
- 如何在ASP.NET中为Craigslist批量发布创建根RDF / XML元素
- asp.net – HttpServerUtility.UrlPathEncode vs HttpServe
- asp.net – 子对象的MVC模型绑定命名约定?
- asp.net – 如何在gridview中将navigateurl添加到超链接
- .Net 更容易的使用配置文件 SuperConfig
- asp.net – 模型在表单发布到控制器时始终为NULL
- asp.net – Oracle中的参数化查询问题
- asp.net – 在ASP中使用其他项目的用户控件
推荐文章
站长推荐
热点阅读