Simple situation
One object User have many UserGroups.
I want to implement on mvc3 form editing or creating action to select UserGroups from drop down.
Controller:
private List<User> GetAllUsers()
{
List<User> users;
users = find all users to List...
return users;
}
public ActionResult Edit(Guid Id)
{
ViewBag.UserGroups = new SelectList(GetAllUsers(), "UserId", "Name");
return View();
}
View:
<div class="editor-label">
@Html.LabelFor(model => model.UserGroupId, "UserGroupId")
</div>
<div class="editor-field">
@Html.DropDownList(WHAT TO PUT HERE ?);
@Html.ValidationMessageFor(model => model.UserGroupId)
</div>
Oh please use a view model, cut that crap of a ViewBag, makes me sick every time I see it.
and then:
and in the view:
but if you wanna make me sick and keep the ViewCrap: