.NET 6 ASP.NET API [Answered]
Hello, I am programming a .NET and currently I am using
[Required], [MaxLength], [MinLength] to validate data transfer objects sent by users in json.
I am wondering is there a better way to validate my DTOs, a week ago someone suggested to use FluentAPI, can someone give me advice?
7 Replies
I've heard good things about FluentValidator. nothing wrong with data annotations either, if they suit your needs.
Thank you, the main issue I'm having with data annotations is being forced to Errors.ParamName format, I wrote express before I wrote C# and I had more control of the messages it would return, with data annotations I feel like I'm forced to a standard that is annoying to handle in the frontend
Is there a way to change that in the annotations? I found some articles on creating custom problem details factories but I'm not sure is it worth the hassle
you can disable it and trigger your own model validation
wdym?
something like this:
then in your controller, you can call ModelState.IsValid
and return your own version of the model state errors
Oh
I didn't know that
Thank you
I will try it out
✅ This post has been marked as answered!