I'm pretty new with asp.net and even if I see some similar question here, I couldn't solve my problem.
I have a list of an object Permission ( compose with an id, a name, a description etc.. ) and I want to use this list to create a multiple select with @Html.ListBoxFor to obtain a select containing option like that:
<option value="Id of the permission">Name of the permission</option>
Here is my controller:
[ChildActionOnly]
public PartialViewResult _GroupAdd(ManagerGroupViewModel groupe)
{
if (groupe != null)
{
//Here isn't important
return PartialView(groupe);
}
else
{
ManagerGroupViewModel grp = new ManagerGroupViewModel();
List<PermissionDTO> list = FactoryBO.Users.PermissionBO.GetAll();
grp.permissionList = list;
return PartialView("_GroupAdd", grp);
}
}
here my partial view:
@using (Ajax.BeginForm("_GroupAdd", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divEmp" }))
{
<form class="col s12">
<div class="row">
<div class="input-field col s12">
@Html.LabelFor(model => Model.groupe.Name, "Group name")
@Html.EditorFor(model => Model.groupe.Name, new { htmlAttributes = new { @class = "validate" } })
@Html.ValidationMessageFor(model => Model.groupe.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="input-field col s12">
</div>
@Html.ListBoxFor(model => model.groupe.Permissions, new SelectList(Model.permissionList) )
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</div>
</form>
}
For the moment, I just obtain this :
<li class="">
<span><input type="checkbox"><label></label>{"Id":FHdqsbg,"Description":"Menu Principal. NOTA: Par defaut ","Name":"AccessMainMenu"}</span>
</li>
if someone can help me :)