ASP.NET MVC 5, I can't get set when I go into edit


I have a service class and in it I have the User responsible for service, which is a user of IdentityUser .

Remembering that I changed the Identity Id from string to "Int", just that.

I can register normally, however, when I go to edit, it lists the users, but does not bring the user who is already registered in the service set.


public class Atendimento
    public int AtendimentoId { get; set; }
    public int UsuarioId { get; set; }

    [Display(Name = "Responsável pelo atendimento")]
    public virtual Usuario Usuario { get; set; }


ViewBag.UsuarioId = new SelectList(db.Users.Select(x => new { UsuarioId = x.Id, Nome = x.Nome + " " + x.Sobrenome }), "UsuarioId", "Nome");


@Html.DropDownList("UsuarioId", null, htmlAttributes: new { @class = "form-control" })

I've already tried to set the property "UsuarioId" to "Id" only, because Identity only uses "Id", it still didn't work.


Another way is to use DropDownListFor.

@Html.DropDownListFor(model => model.UsuarioId, new SelectList(ViewBag.Usuarios, "UsuarioId", "Nome"))

You say which property of your model should be used to set the value and which list should fill the options.

Scroll to Top