0

I have this in my edit controller:

playerView.Users = new SelectList(repo.GetUsers(), "UserID", "UserName", player.User.UserID.ToString());

and this is how looks my dropdownlist:

@Html.DropDownListFor(x => x.SelectedUserID, Model.Users)
@Html.ValidationMessageFor(x => x.SelectedUserID)

But I can´t get that selected user to my view (I always get first item in dropdownlist). In player.User is User with id, name, ... I tried UserID with or without ToString, UserName or just User but nothing helps. Thanks

1 Answer 1

3

Try like this:

...
playerView.Users = new SelectList(repo.GetUsers(), "UserID", "UserName");
playerView.SelectedUserID = player.User.UserID.ToString();
return View(playerView);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.