asp.net-mvc – 将动作方法参数传递给asp.net mvc中的ActionFilt
发布时间:2020-12-15 18:31:33 所属栏目:asp.Net 来源:网络整理
导读:我知道我可以使用filterContext来获取它。但是,如果action方法参数的名称不同,则这不是很灵活。这应该工作: [HttpGet][NewAuthoriseAttribute(SomeId = id)]public ActionResult Index(int id){ ...public class NewActionFilterAttribute : ActionFilter
我知道我可以使用filterContext来获取它。但是,如果action方法参数的名称不同,则这不是很灵活。这应该工作:
[HttpGet] [NewAuthoriseAttribute(SomeId = id)] public ActionResult Index(int id) { ... public class NewActionFilterAttribute : ActionFilterAttribute { public int SomeId { get; set; } ... 但它并不(甚至不编译)。有任何想法吗? 解决方法
建立在@Pankaj的答案和@csetzkorn的评论:
将参数的名称作为字符串传递,然后检查filterContext public class NewAuthoriseAttribute : ActionFilterAttribute { public string IdParamName { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext.ActionParameters.ContainsKey(IdParamName)) { var id = filterContext.ActionParameters[IdParamName] as Int32?; } } } [NewAuthorizeAttribute(IdParamName = "fooId")] public ActionResult Index(int fooId) { ... } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 实现访问者计数器
- asp.net – 如何手动获取.aspnet.cookies Cookie中的信息?
- asp.net-mvc – 表达式树可能不包含动态操作 – mvc
- asp.net-mvc – 只发布控制器
- asp.net – 在MVC 4.0中使用部分视图中的节
- ASP.Net数据库配置
- 如何缓存输出的action方法,返回图像到asp.net mvc中的视图?
- asp.net – 如何从mvc .net web app中的jquery(在自定义视图
- AspNetCore.Authentication.JwtBearer失败,没有SecurityTok
- asp.net – 尝试通过方法’HttpConfiguration..ctor(HttpRo
推荐文章
站长推荐
- DevExpress v17.2新版亮点—ASP.NET篇(三)
- .net – 提供“添加到日历”链接
- asp.net-mvc-3 – MVC3:用于发送表单(模型)值和
- asp.net – Request.IsAuthenticated永远不会成立
- 如何在IIS7 for ASP.NET中创建虚拟目录?
- asp.net – 如何访问嵌套母版页中的控件?为什么
- asp.net-mvc-3 – MVC3 / Razor添加控制器“Get-
- asp.net-core – VS 2017安装后无法运行基于proj
- asp.net-mvc – 使用web.config关闭MVC中的身份验
- 如何在ASP.NET中运行.py(Python)文件?
热点阅读