2

I have to modify auto validation response that [ApiController] generates but only for some endpoints, so I can't change ApiBehaviorOptions. I tried using IActionFilter, but the auto validation is done before action filter and I can't modify it this way.

How can I modify auto validation response for some actions only?

Szyszka947
  • 473
  • 2
  • 5
  • 21
  • Custom Attribute that you'll have to handle on both the client and server: https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#custom-attributes – GH DevOps Jan 27 '23 at 20:31
  • I mentioned about API, so I dont need to handle anything on client. What's more, I'm not asking how to create custom validation attribute, but how to modify validation response auto generated by `ApiController`. – Szyszka947 Jan 28 '23 at 11:09
  • If you want the validation message to change for all Actions, you can add the `ErrorMessge` attribute to auto validation. If you want to [use the action filter to handle the Validation failure error response](https://stackoverflow.com/a/64280264/18789859), you need to remove or disable auto validation response. It looks like you cannot modify the default auto-validation message for the specified Action. – Chen Jan 31 '23 at 05:53

0 Answers0