Changing ActionExecutingContext values in Custom Filter Attribute
I have a custom filter attribute that I want to use on certain ActionResults to look at the data being attempted a开发者_如何学Cnd to set values where certain rules are violated.
So;
public class SpecialActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
foreach (string value in filterContext.Controller.ValueProvider.Keys)
{
string h = filterContext.Controller.ValueProvider[value].AttemptedValue;
if (h == "1")
{
//set the value of the key to be say "one".
}
}
base.OnActionExecuting(filterContext);
}
}
is this possible?
You can inspect or modify the parameters that will be passed to the action - see the ActionExecutingContext.ActionParameters property for this. This is a very general solution, though. If you could provide a little more context on what exactly you're trying to do, we might be able to provide more relevant suggestions.
精彩评论