-1
Hello! I would like to know if Dataannotation is compatible with Json, because I am validating a form and I would like to ask the question. I am using Angular on the front and returning my object in Json format, I would like to validate the return of that json (the information that the user typed in the fields) using Dataannotation
That’s my method of adding:
[HttpPost]
public async Task<string> Add([FromBody]Sindicate objSindicate)
{
return JsonConvert.SerializeObject(await _service.Add(objSindicate));
}
This is my class using Dataannotation.
public class SindicateValidator
{
[Key]
public Guid SindicateId { get; set; }
[Required(ErrorMessage = "Nome obrigatório!")]
[MaxLength(128, ErrorMessage = "Máximo {0} caracteres")]
[MinLength(2, ErrorMessage = "Minímo {0} caracteres")]
public string Name { get; set; }
[Required(ErrorMessage = "Razão Social é obrigatório!")]
[MaxLength(128, ErrorMessage = "Máximo {0} caracteres")]
[MinLength(2, ErrorMessage = "Minímo {0} caracteres")]
public string SocialReason { get; set; }
[Required(ErrorMessage = "CNPJ é obrigatório!")]
[DisplayFormat(DataFormatString = "{0:n2}",
ApplyFormatInEditMode = true)]
[MaxLength(14, ErrorMessage = "Máximo {0} caracteres")]
public string CNPJ { get; set; }
[Required(ErrorMessage = "Login é obrigatório!")]
[MaxLength(128,ErrorMessage = "Máximo {0} caracteres")]
public string Login { get; set; }
[Required(ErrorMessage = "Senha é obrigatório!")]
[MaxLength(8, ErrorMessage = "Máximo {0} caracteres")]
public string Password { get; set; }
[Required(ErrorMessage = "E-Mail é obrigatório!")]
[MaxLength(128, ErrorMessage = "Máximo {0} caracteres")]
[EmailAddress(ErrorMessage = "Preencha um E-mail válido!")]
public string Email { get; set; }
[ScaffoldColumn(false)]
public DateTime DateCreated { get; set; }
[ScaffoldColumn(false)]
public bool Disable { get; set; }
[ScaffoldColumn(false)]
public DateTime? DateDisable { get; set; }
[ScaffoldColumn(false)]
public bool Deleted { get; set; }
[ScaffoldColumn(false)]
public DateTime? DateDeleted { get; set; }
}
Expose what you already have and explain your problem better.
– Leandro Angelo