Set item in ViewData or of a viewmodel if you pass it as a parameter into your action.
Here I set the property of a ViewModel
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
ViewModelBase viewModel = null;
foreach (object parameter in filterContext.ActionParameters.Values)
{
if (parameter is ViewModelBase)
{
viewModel = (ViewModelBase)parameter;
break;
}
}
if(viewModel !=null)
{
viewModel.SomeProperty = "SomeValue";
}
}
public ActionResult About(ViewModelBase model)
{
string someProperty= model.SomeProperty;
}
EDIT
Here is the untyped version I think you prefer:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.Controller.ViewData.Add("TestValue", "test");
}
[FilterWhichSetsValue]
public ActionResult About()
{
string test = (string)ViewData["TestValue"];
return View();
}