Reputation: 1
I have a problem with my ApiController. I don't know why I'm getting an error 400 for not required list when I send empty NestedClasses or any empty property for NestedClass in request. I don't use DataAnonations attribute [Required], but response indicates that NestedClasses and all property in NestedClass are required.
public class TestModel
{
public List<NestedClass> NestedClasses { get; set; }
public string TestProperty { get; set; }
}
Thank you for your advices.
Upvotes: 0
Views: 136
Reputation: 404
You can make the list nullable by using "?" so it will accept nulls.
public List<NestedClass?> NestedClasses { get; set; }
Also you might need to check the nullability of the properties in the NestedClass class to make them accept nulls.
Upvotes: 0
Reputation: 9112
To eliminate the warnings from nullable reference types, remove the following line from the yourproject.csproj file:
<Nullable>enable</Nullable>
Upvotes: 1