由于数据模型中的项目未在表单中显示,Blazor 表单验证失败

Blazor form failing validation due to items in the data model that are not shown in the form

我有一个使用几个 EditForms 的 Blazor(服务器端)项目。在每种情况下,数据模型都恰好包含表单中不需要的嵌套对象。我发现如果该对象被视为无效但没有任何解释,则该表单将无法通过验证。有没有一种方法可以检查表单确定提交事件无效的具体原因?

谢谢!

Simon,查看此信息microsoft docs,关于

ObjectGraphDataAnnotationsValidator, ValidateComplexType

当您将属性 (ValidateComplexType) 放在嵌套对象上并将“DataAnnotationsValidator”替换为“ObjectGraphDataAnnotationsValidator”时,在主编辑表单中的所有内容均有效后,您将看到嵌套对象的错误信息。