asp.net-mvc – 如何将变量传递给ASP.NET MVC应用程序中的自定义
发布时间:2020-12-15 23:34:28 所属栏目:asp.Net 来源:网络整理
导读:我有一个控制器在我的MVC应用程序,我正在尝试使用自定义ActionFilterAttribute记录细节,通过使用onResultExecuted方法. I read this tutorial了解和编写我自己的动作过滤器.问题是如何将变量从控制器传递给动作过滤器? 我想得到调用控制器的输入变量.说,用
我有一个控制器在我的MVC应用程序,我正在尝试使用自定义ActionFilterAttribute记录细节,通过使用onResultExecuted方法.
I read this tutorial了解和编写我自己的动作过滤器.问题是如何将变量从控制器传递给动作过滤器? >我想得到调用控制器的输入变量.说,用户名/用户ID. 控制器 – [MyActionFilter] public class myController : ApiController { public string Get(string x,int y) { .. } public string somemethod { .. } } 动作过滤器 – public class MyActionFilterAttribute : ActionFilterAttribute { public override void onActionExecuted(HttpActionExecutedContext actionExecutedContext) { // HOW DO I ACCESS THE VARIABLES OF THE CONTROLLER HERE // I NEED TO LOG THE EXCEPTIONS AND THE PARAMETERS PASSED TO THE CONTROLLER METHOD } } 我希望我在这里解释这个问题.道歉,如果我在这里错过了一些基本的对象,我完全是新的. 解决方法
方法 – 1
动作过滤器 public class MyActionFilter : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { base.OnActionExecuted(filterContext); } } 行动方法 [MyActionFilter] public ActionResult Index() { ViewBag.ControllerVariable = "12"; return View(); } 如果您注意截图,可以看到ViewBag信息 方法 – 2 动作过滤器 public class MyActionFilter : ActionFilterAttribute { //Your Properties in Action Filter public string Property1 { get; set; } public string Property2 { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); } } 行动方法 [MyActionFilter(Property1 = "Value1",Property2 = "Value2")] public ActionResult Index() { return View(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 对我来说MVC?
- asp.net – 如何使用css文件创建圆角按钮?
- asp.net-mvc-3 – 自定义RazorViewEngine会出现页面错误
- asp.net-mvc – ASP.NET MVC2母版页 – 服务器端脚本无法渲
- 有没有相当于PrimeFaces for ASP.NET的东西?
- 基于ASP.net的开源支持票系统
- asp.net – 如何在umbraco中添加波斯语或其他语言Datatimep
- asp.net-mvc-3 – 如何在MVC3中为iframe的src属性提供html文
- asp.net-mvc – Route Constraint Isnt适用于ASP.NET MVC
- 在ASP.NET MVC表单上允许多个按钮的最佳方法是什么?
推荐文章
站长推荐
- asp.net-core – 来自带有Entity Framework Core
- asp.net – Dotnetopenauth,从facebook范围检索电
- asp.net-mvc – 重置asp.net mvc路由而不重置应用
- Asp.Net MVC UNITOfWork和MySQL和睡眠连接
- asp.net-mvc-3 – MVC 3脚手架可用于n层应用吗?
- ASP.NET路由:令牌之间的字面子段和来自文字子段
- asp.net-mvc – 帮助/提示提高我的ASP.NET MVC 2
- 如何避免异常捕获.NET中的复制粘贴
- asp.net-mvc – ASP.NET web api – 设置自定义I
- asp.net – PostbackUrl vs NavigateUrl
热点阅读