What a good practice for using Modelbinders in MVC

Asked

Viewed 50 times

1

I’m looking to create a page using best practices in ASP.NET MVC.

I was in doubt what would be the best practice for me to model my page using modelbinders to "bindar" my object automatically. In this case, my doubt was in the relationships between the classes, see for example my scenario:

    public class Pessoa
    {
        [Key]
        public int ID { get; set; }
        public string Nome { get; set; }
        public Perfil Perfil { get; set; }
    }

    public class Perfil 
    {
        [Key]
        public int ID { get; set; }
        public string Nome { get; set; }
    }

In my view, it would look something like this:

 @model Pessoa

 <div class="col-md-3">
            @Html.TextBoxFor(c => c.Pessoa.naturezaOcorrencia, Model.GetStatus())
 </div>

 <div class="col-md-3">
            @Html.DropDownListFor(c => c.Perfil, ???????)
 </div>

So, how would I finish filling the Dropdownlist. It does not accept a direct list from Entity for example: Perfil.All().ToList();

1 answer

1


In this case would be:

@Html.DropDownListFor(c => c.Perfil, new SelectList(SEU MODEL, "ID", "Nome"), "Selecione o Perfil")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.