i have defined an action filter like this:
public class InvokeConditionAttribute : ActionFilterAttribute
{
private ConditionRule conditionRule;
public InvokeConditionAttribute(ConditionRule conditionRule)
{
this.conditionRule = conditionRule;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// check condition rule
}
}
ConditionRule in parameter is a enum type. then i create a controller like below:
[InvokeCondition(ConditionRule.Condition1, Order = 1)]
public class AttendanceModificationController : Controller
{
[InvokeCondition(ConditionRule.Condition2, Order = 2)]
public ActionResult SomeAction()
{
//
}
}
problem is method level filter not invoke.
can define same filter type with different parameter in asp.net mvc?
Decorate your action filter with the AttributeUsage attribute and specify the AllowMultiple = true:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public class InvokeConditionAttribute : ActionFilterAttribute
{
...
}
Now your OnActionExecuting method will be triggered twice for the SomeAction action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With