2010-01-06 67 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屬性用於此。不過,這是一個非常通用的解決方案。如果你可以提供更多關於你想要做什麼的背景,我們可能會提供更多相關的建議。

相關問題