WebApi
WebApi copied to clipboard
ModelState validation and OData
Is ASP.NET Core MVC model validation supposed to happen with an OData controller?
I have an entity marked up with StringLength
attributes, but when it hits the controller the ModelState is valid.
This causes a problem as EF Core no longer validates before submitting, I just get a "String or binary data was truncated" error from SQL Server with no indication of which property has an issue.
Assemblies affected
Microsoft.AspNetCore.OData 7.1.0 Microsoft.AspCore 2.2.0
Expected result
ModelState should be invalid
Actual result
ModelState is valid even though StringLength is exceeded.
I haven't tried the StringLengthAttribute
yet but I'm using MinLengthAttribute
and MaxLengthAttribute
and for me they work fine. The ModelState is not valid as expected when the call hits the controller. Maybe you can give this a try until the actual problem is identified 😉
Any updates on this?