When debugging an ASP.NET Core Controller, my breakpoint in the action method was never hit.
It took me some time to figure out why this was happening. It turns out that my model wasn’t valid. ASP.NET Core has a default ModelStateInvalidFilter. This filter is executed before the controller method is executed. So when the ModelState is invalid, the code in the controller is never executed explaining why my breakpoint is never hit.
If you want, you can suppress this filter:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.Configure<ApiBehaviorOptions>(options => | |
{ | |
options.SuppressModelStateInvalidFilter = true; | |
}); | |
} |
Be aware that this disables the filter globally.