3
I want to create a class attribute for sex (M or F), that by default one can already select. It is possible to create an array with these values (M and F) already default without having to type, or should do so in the same layout?
[DisplayName("SEXO")]
[StringLength(1, MinimumLength = 1, ErrorMessage = "Selecione o Sexo")]
public string Sexo { get; set; }
The way it is here (above) would be a field for the person to type, I thought to do like a:
public list<Sexo>...
AMENDING
namespace Projeto.Models
{
public enum Sexo { M = 1, F = 2 }
public class Pessoa
{
[Key]
public int PessoaID { get; set; }
[DisplayName("Nome")]
[Required(ErrorMessage = "Preencha o nome")]
[StringLength(255, MinimumLength = 3, ErrorMessage = "O nome deve ter de 3 a 255 caracteres")]
public string Nome { get; set; }
...
[DisplayName("SEXO")]
[Required(ErrorMessage="Selecione o sexo")]
[StringLength(1, MinimumLength = 1, ErrorMessage = "Selecione o Sexo")]
public Sexo Sexo { get; set; }
}
}
in making Add-Migration
I receive the following message:
If you can use a
Enum
in the case!– novic
thus?
public enum Sexo { M, F }
? but it wouldn’t have to have the{Get; Set;}
??– Fabio Souza
I put in a reply!
– novic
It worked for you @Fabiosouza ???
– novic
So Virgil, I did, but I haven’t tested the functionality yet, so test and work, I mark as accepted. Thank you for so far
– Fabio Souza
Remove that Stringlenght and the problem
– novic