'Doesn't reach OnActionExecutionAsync

I have this filter in .NET 6 web app project.

public class ValidationFilter : IAsyncActionFilter
{
    public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
    {     
        await next();
    }
}

and in my Program.cs

builder.Services.AddControllersWithViews(options =>
{
    options.Filters.Add<ValidationFilter>();
});

and this is my validator class. I am using Fluent validation

public class MarketingEventRequestValidator : AbstractValidator<CreateMarketingEventRequest>
{
    public MarketingEventRequestValidator()
    {
        RuleFor(marketingEventRequest => marketingEventRequest.Name).NotNull().NotEmpty();
        RuleFor(marketingEventRequest => marketingEventRequest.EventDate).NotNull().NotEmpty()
            .Must(BeAValidEventDate).WithMessage("Event date must be equal or greater than system date");
        RuleFor(marketingEventRequest => marketingEventRequest.StartTime).NotNull().NotEmpty().Length(4);
        RuleFor(marketingEventRequest => marketingEventRequest.EndTime).NotNull().NotEmpty().Length(4);
    }
    private bool BeAValidEventDate(DateTime date)
    {
        return date < DateTime.Now;
    }
}

and in my controller

public async Task<ActionResult> AddMarketingEvent([FromBody] CreateMarketingEventRequest request)
        {
         // code removed for brevity            
        }

But when I put a breakpoint to test it, it doesn't reach OnActionExecutionAsync

Anything I miss out?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source