开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜