2
I have a Personal E-nature that relates to the Person table. I need to create a dropdownlist in my view that displays the list of Personsnaturezas (PESSOA FÍSICA E PESSOA JURÍDICA), including showing people related to the current record, according to the viewmodel. Someone knows how to help me?
Personal nature
public enum PessoaNatureza
{
[Description("FÍSICA")]
Fisica = 1,
[Description("JURÍDICA")]
Juridica = 2
}
Personal
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>
related: https://stackoverflow.com/questions/61953/how-do-you-bind-an-enum-to-a-dropdownlist-control-in-asp-net
– novic
other: https://answall.com/questions/95375/choose-quais-itens-de-um-enumerador-aparece-em-um-enumdropdownlistfor
– novic