I’m using this approach using viewmodel for manipulating values inside combo boxes. Now, I’m struggle to select as default value actual selected value used in create action, not the first one from combo. I know this is fourth parameter in SelectList but I do not know how to use actual UserGroupId cause it’s give me an error when using like these
var model = new UserViewModel
{
UserGroups = new SelectList(GetAllUsers(), "UserId", "Name", UserGroupId)
}
return View(model);
public class UserViewModel
{
public int UserGroupId { get; set; }
public IEnumerable<SelectListItem> UserGroups { get; set; }
}
Like this:
and in your view: