Hi all, this may not (probably isn't) related to ASPNETCORE but that's what I'm currently toying with, so I'm putting it here...
I have a complex type that I'm binding in a Razor Page property with "BindProperty" attribute.
Model: THING1
string (required)
int
string
IList <THING2>
Model: THING2
string (required)
int
int
The object and the code works fine and as expected with one exception, when one of the "sub types" is missing a mandatory/validation element the form submit "successfully fails" but with NOTHING in the ModelState (and therefore nothing shows in the "Validation summary" control).
Stepping through in the debugger I noticed that the ModelState on the POST operation looks like this: (kind of like reported here,https://github.com/aspnet/Mvc/issues/4978 , but there is legitimate error in this instance)
"items" 15
1->ValidationState Validated
2->ValidationState Validated
...
4 ->ValidationState Unvalidated
5 ->ValidationState Unvalidated
...
So, for example, if you submit 3 THING2s in the THING1 details page, but the 2nd one is misssing the "required string" you will get:
ModelState.IsValid == false
But there are NO ERRORS in the ModelState to display the user that the field is required...
**I SUSPECT this is because the ModelState is parent level only, andlists are considered separate models, somehow... but I don't understand how one is supposed to address this kind of issue...
eg: it is not unreasonable to expect a "person" with multiple contact (phone) types/numbers or addresses to be listed/updateable on an object like this in a UI...
Any guidance appreciated. (and if the solution is, as in the above github, to use both a custom IModelBinder and IModelBinderProvider, are there any tips/tricks to keeping the complexity of this low, because the model binding I've got WORKS, just not the validation...)