WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

ModelState validation and OData

Open phatcher opened this issue 5 years ago • 2 comments

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.

phatcher avatar Jun 16 '19 09:06 phatcher

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 😉

Danielku15 avatar Jun 17 '19 15:06 Danielku15

Any updates on this?

rahul7720 avatar Mar 03 '22 08:03 rahul7720