How Can I Use Data Annotations Attribute Classes to Fail Empty Strings in Forms?

前端 未结 4 2151
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 02:10

I was trying to require a text input field in a form, which implies that there needs to be something in the form. However, adding a [Required] tag to my model w

4条回答
  •  心在旅途
    2020-12-09 02:34

    You can add a DefaultValueAttribute to the property that requires a default value (e.g. string.Empty for UserName)

    [DisplayName("User Name")]
    [System.ComponentModel.DefaultValue("")]
    public string UserName { get; set; }
    

提交回复
热议问题