I have an enum PersonNature that relates to the Person table. I need to create a dropdownlist in my view that displays the list of PeopleNature (PHYSICAL AND LEGAL PERSON), including showing the personal nature related to the current record, according to the viewmodel. Does anyone know how to help me?
PeopleNature
public enum PessoaNatureza
{
[Description("FÍSICA")]
Fisica = 1,
[Description("JURÍDICA")]
Juridica = 2
}
PersonaViewModel
public class PessoaViewModel
{
[Key]
[DisplayName("Código")]
public int Id { get; set; }
[DisplayName("Natureza")]
[Display(Name = "Natureza")]
[RegularExpression(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")]
[Required(ErrorMessage = "Escolha uma Natureza de Pessoa")]
public int PessoaNaturezaId { get; set; }
public List<SelectListItem> PessoasNaturezas { get; set; }
}
Edit.cshtml
<div class="form-group">
<label asp-for="PessoaNaturezaId" class="col-md-2 control-label"></label>
<div class="col-md-2">
<input asp-for="PessoaNaturezaId" class="form-control" />
@Html.DropDownListFor(model => model.PessoaNaturezaId, Model.PessoaNatureza, "--Selecione--", new { @class = "form-control" })
<span asp-validation-for="PessoaNaturezaId" class="text-danger"></span>
</div>
</div>