ModelState.IsValid even when it should not be?

前端 未结 10 1372
说谎
说谎 2020-11-29 03:14

I have API where I need to validate my user model. I choose an approach where I create different classes for Create/Edit actions to avoid mass-assignment and divide validati

10条回答
  •  一个人的身影
    2020-11-29 03:41

    There is a simple Solution for your problem

    public class UserCreate
    {
        [Required(AllowEmptyStrings = false)]
        public string Username { get; set; }
    }
    

    Here AllowEmptyStrings = false can be used for your validation

提交回复
热议问题