ASP.NET MVC 将对象从自定义操作过滤器传递到操作 [英] ASP.NET MVC Pass object from Custom Action Filter to Action
本文介绍了ASP.NET MVC 将对象从自定义操作过滤器传递到操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在 ASP.NET MVC 的自定义操作过滤器中创建一个对象
If I create an object in a Custom Action Filter in ASP.NET MVC in
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
DetachedCriteria criteria = DetachedCriteria.For<Person>();
criteria.Add("stuff");
// Now I need to access 'criteria' from the Action.....
}
有什么方法可以从当前正在执行的 Action 中访问该对象.
is there any way I can access the object from the Action that is currently executing.
推荐答案
我建议把它放在 Route 数据中.
I would recommend putting it in the Route data.
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.RouteData.Values.Add("test", "TESTING");
base.OnActionExecuting(filterContext);
}
public ActionResult Index()
{
ViewData["Message"] = RouteData.Values["test"];
return View();
}
这篇关于ASP.NET MVC 将对象从自定义操作过滤器传递到操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文