I need a way to set Database retrieve values in a multi select drop down in a edit view in a web application (ASP.NET, Mvc) (load drop down with selected values when page loaded)
from view code,I passed selected ids in to selected values array.(when I return values from DB , assign those in to a array then assign to here.
I need a edit view by set selecting already selected values.
//View
<div class="form-group">
<label>Choose Categories</label>
@Html.DropDownListFor(model => model.SelectedValues, new MultiSelectList(Models.GetCategoryList().OrderBy(c => c.Value), "Key", "Value"), "Select Category", new { @class = "chzn-select form-control", multiple = "multiple" })
</div>
//Model
public int[] SelectedValues { get; set; }
//Controller
public ActionResult Edit(int id)
{
return View(GetDetails(id));
}
In GetDetails(id) take values from DB , and return a model object
public GetDetails()
{
int[] arr = new int[2];
arr[0] = 4;
arr[1] = 5;
modelObj.SelectedValues = arr;
.......
......
return modelObj;
}
please anyone suggest way to do this
Thank you.