If you just leave it like this:
[Required, StringLength(150, ErrorMessage = "Insira no máximo 150 caracteres")]
The custom message will shoot only for the string with a maximum size of 150 characters. And so will be the same thing
[Required]
[StringLength(150, ErrorMessage ="Insira no máximo 150 caracteres")]
If you are using jquery validate a standard message will be sent to Required, but if you want to leave the custom message:
[Required(ErrorMessage = "O campo xxx deverá ser preenchido!)]
And I think the best way is to use it as in the example:
public class Produto
{
[Key]
[Column(Order = 0)]
public int ID { get; set; }
[Required(ErrorMessage = "Digite o nome do produto."), Column(Order = 1)]
[MinLength(5, ErrorMessage = "O tamanho mínimo do nome são 5 caracteres.")]
[StringLength(200, ErrorMessage = "O tamanho máximo são 200 caracteres.")]
public string Nome { get; set; }
[Display(Name="Quantidade")]
[DisplayFormat(DataFormatString = "{0:n2}",
ApplyFormatInEditMode = true,
NullDisplayText = "Estoque vazio")]
[Range(10, 25, ErrorMessage = "A Qtde deverá ser entre 10 e 25.")]
[Column(Order = 2)]
public double Qtde { get; set; }
[DisplayFormat(DataFormatString = "{0:n2}",
ApplyFormatInEditMode = true,
NullDisplayText = "Sem preço")]
[Range(3, 500, ErrorMessage = "O preço deverá ser entre 3 e 500.")]
[Column(Order = 3)]
public decimal Preco { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
[Column(Order = 4)]
[Display(Name="Vencimento")]
public DateTime Dt_Vencto { get; set; }
}
You mean, in separate lines or together?
– Maniero
@mustache, that. If I wear the
Required
on the same line as theStringLength
or in different lines, as I always see around.– Renan Carlos