I need a way to set already selected values in a multi select dropdown in a edit view in a web application (ASP.NET, Mvc 5) :
<div class="form-group">
<div class="col-md-10">
@Html.DropDownList("EntityId", selectList: (IEnumerable<SelectListItem>)ViewBag.EntityId, htmlAttributes: new { @class = "form-control select2", multiple = "multiple" })
</div>
</div>
//Controller
ViewBag.EntityId = new SelectList(context.CompanyEntity.Where(x => x.UserProfile.Any(u => u.UserProfileId == id)), "EntityId", "EntityName");
I need a edit view by set selecting already selected values.