【问题标题】:RequiredIf conditional attribute in .net Core.net Core 中的RequiredIf 条件属性
【发布时间】:2020-03-26 18:20:40
【问题描述】:

如何在 .NET Core 中实现 RequiredIf 条件操作以进行基于模型的验证。

在 ASP.NET MVC 中,曾与 ExpressiveAnnotation 包一起使用,但它不适用于 .NET Core。

【问题讨论】:

    标签: asp.net-core-2.1 .net-core-3.0 model-validation expressiveannotations


    【解决方案1】:

    UoN.ExpressiveAnnotations.NetCore 是用于 .NET Core 应用程序的包,其功能与用于 MVC 的 ExpressiveAnnotation

    参考网址:https://github.com/uon-nuget/UoN.ExpressiveAnnotations.NetCore

    【讨论】:

      【解决方案2】:

      您可以扩展RequiredAttribute 来检查属性值,并据此手动检查当前属性的 IsNullOrWhiteSpace。

      您可以找到代码示例hereHere 是另一个使用自定义 ValidationAttribute 的代码示例。

      【讨论】:

        猜你喜欢
        • 2011-11-15
        • 1970-01-01
        • 2014-06-15
        • 2019-11-28
        • 1970-01-01
        • 2013-08-13
        • 1970-01-01
        • 2020-02-23
        • 2021-08-04
        相关资源
        最近更新 更多