【问题标题】:Allowing just white space in 'Required' data annotation在“必需”数据注释中只允许空格
【发布时间】:2012-01-10 01:04:05
【问题描述】:

我在字符串上使用[Required] 数据注释。这按预期工作,但是它认为由空格组成的输入 just 无效。

有什么办法可以改变吗?

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    RequiredAttribute 上有一个 AllowEmptyStrings 属性。看看有没有帮助。

    https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.requiredattribute.allowemptystrings

    【讨论】:

      【解决方案2】:

      根据MSDN可以使用AllowEmptyStrings

       [Required(AllowEmptyStrings = false)]
       public string CompanyName { get; set; }
      

      【讨论】:

        猜你喜欢
        • 2016-03-24
        • 1970-01-01
        • 1970-01-01
        • 2016-09-03
        • 1970-01-01
        • 2013-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多