2010-01-06 93 views
0

我有一个自定义过滤器属性,我想在某些ActionResults上使用它来查看正在尝试的数据并设置违反某些规则的值。在自定义过滤器属性中更改ActionExecutingContext值

所以;

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); 
    } 

} 

这是可能的吗?

回答

1

您可以检查或修改将被传递到操作的参数 - 看到ActionExecutingContext.ActionParameters属性用于此。不过,这是一个非常通用的解决方案。如果你可以提供更多关于你想要做什么的背景,我们可能会提供更多相关的建议。

相关问题