Polymorphic binder: validation not working when custom model bound is wrapped in another class
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Bug description
When changed the official sample PolymorphicModelBinding to:
- Validate `CPUIndex `and `ScreenSize` (e.g. with `Required` attribute)
- Wrap the `Device` class
Adapting the other code, to corespond with the new model structure and running the sample, the **model is bound correctly, but not validated**.
### To Reproduce
[https://github.com/zoka-cz/AspNetCore.Docs/tree/master/aspnetcore/mvc/advanced/custom-model-binding/3.0sample/PolymorphicModelBinding](https://github.com/zoka-cz/AspNetCore.Docs/tree/master/aspnetcore/mvc/advanced/custom-model-binding/3.0sample/PolymorphicModelBinding)
Just few changes to the official sample on my fork.
1. build and run
2. click the "Add device" link
3. Keep default values (Laptop kind, empty CPUIndex, empty ScreenSize)
4. Click "Add" button
5. Observe, that the device was correctly added, while there is `[Required]` attribute on the CPUIndex property, and it should gives you the validation error.
6. Original sample where the `Device` class is not wrapped, with [Required] attributes added to the mentioned properties is validated correctly.
### Exceptions (if any)
No exception.
### Further technical details
- ASP.NET Core version 3.0.1
- The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version: Microsoft Visual Studio Community 2019 Version 16.8.1
Contributor guide
Assessment
This issue has not been assessed yet.