我有一个从action filter属性派生的自定义验证属性。目前,该属性只是设置一个ActionParameter值,指示验证的项目是否良好,然后该操作必须具有逻辑来确定如何处理信息。
public class SpecialValidatorAttribute: ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// ... valdiation work done here ...
filterContext.ActionParameters["SpecialIsValid"] = resultOfWork;
base.OnActionExecuting(filterContext);
}
}
[SpecialValidator]
public ActionResult Index(FormCollection collection, bool SpecialIsValid)
{
if(!SpecialIsValid)
// add a modelstate error here ...
// ... more stuff
}
我已尝试将ModelState属性添加到属性中,但该数据似乎无法传递到属性中。
有没有办法从属性中访问ModelState?