从自定义操作筛选器操作ASP.NET MVC通行证对象 [英] ASP.NET MVC Pass object from Custom Action Filter to Action

查看:177
本文介绍了从自定义操作筛选器操作ASP.NET MVC通行证对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    DetachedCriteria criteria = DetachedCriteria.For<Person>();
    criteria.Add("stuff");

    // Now I need to access 'criteria' from the Action.....

}

有什么办法,我可以从当前正在执行的行动访问对象。

is there any way I can access the object from the Action that is currently executing.

推荐答案

我会建议把它在路径数据。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆