Is it possible to access the TempData key/value from HttpContext?

Richard77 picture Richard77 · Nov 23, 2010 · Viewed 8.6k times · Source

I'm trying to crate a custom action filter attribute. And some where, I need facilities, such us TempData[key] and TryUpdateModel... My custom attribute class deriving from the ActionFilterAttribute, I can access both below methods.

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
}

Unfortunately, from both filtercontext local variables, I don't know how to access the TempData. I've tried to follow several leads, but without success. After all, maybe there's TempData in the filterContext variables. In that case, how do I access the TemData available?

Thanks for helping

Answer

Darin Dimitrov picture Darin Dimitrov · Nov 23, 2010
var foo = filterContext.Controller.TempData["foo"];