November Happy Hour will be moved to Thursday December 5th.

ModelState is not valid

EVT
EVT
Vote:
 

Did anyone else run into an issue after project upgrade that now Microsoft.AspNetCore.Mvc ModelState is validating not just controller's model?

We have an issue that a customer cannot end purchase journey because there a required field in home page that is not filled in. 

#306230
Aug 04, 2023 9:24
Vote:
 

Hi EVT

Is your project having nullable feature enabled? Can you check your csproj file? If your application is built with nullable enabled and by default mvc will validate all non-nullable properties or parameters. That's the fundamental change with nullable feature enabled from what I understand.

Unfortunately I don't have much information from what you described above, I hope my answer would help.

#306575
Aug 10, 2023 12:53
EVT
Vote:
 

I have posted my question on StackOverflow. Unfortunately I cannot remove the inheritance so I have written a custom validation rather than using ModelState.IsValid. 

#306624
Aug 11, 2023 8:30
Vote:
 

I don't quit get it. Your issue does not seem related to inheritance. Do you have nullable enabled?

If the issue is caused by nullable reference type, you can disable this behavior using the following code

builder.Services.AddControllers(
    options => options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true);

#306629
Aug 11, 2023 9:30
EVT
Vote:
 

I have a property in a class that is null BUT that entire class should not be validated.

It is a property in a Home page while the controller / view model / class is a Billing page. 

And it did not work this way before the change (Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator and System.Web.Mvc.ModelStateDictionary)

#306634
Aug 11, 2023 9:34
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.