I m using chosen jquery plugin for multiselect list.my problem is it is not showing selected value in edited form.
my controler code is
ArrayList selectedrole = new ArrayList();
foreach (var role in employee.CompanyRoles)
{
selectedrole.Add(role.CompanyRoleId.ToString());
}
[ViewBag.CompanyRoleId = new SelectList(CompanyRole, "CompanyRoleId", "RoleName", selectedrole);]
my view code
<div class="editor-label">
Role
</div>
<div class="editor-field">
@Html.ListBox("emprole", ViewBag.CompanyRoleId as MultiSelectList , new
{
@class = "chzn-select",
data_placeholder = "Choose Role...",
style="width:350px;"
})
</div>
and my script
$(".chzn-select").chosen({ allow_single_deselect: true });
can any body tell me what i m doing wrong it is not showing selected value when form is displaying in edited mode.
In the code below
selectedroleis expected to be of the same type as the objects inCompanyRoles. It also only allows one item to be selected.You need to use
MultiSelectListinstead.