I am receiving an error that I cannot figure out and even previously answered questions are not binding the ListBox the same way I am.
Here is how I use the ListBox on my create view:
ASP.NET MVC Return Comma Delimited String From From ListBoxFor To Controller
Now when I go to my edit I receive this error:
The parameter 'expression' must evaluate to an IEnumerable when
multiple selection is allowed.
On this code:
@Html.ListBoxFor(model => model.Mask_Concat, Enumerable.Empty<SelectListItem>(), new { @class = "chosen-container chosen-container-multi", @style = "width:300px" })
I have tried everything I can think of, binding the ListBox to a ViewModel, still no luck.
Model:
public string Mask_Concat { get; set; }
View:
<div class="fancy-form" id="mainMask">
@Html.LabelFor(model => model.Mask_Concat, "Mask(s)", new { @class = "control-label col-md-2" })
<div class="col-md-12">
@Html.ListBoxFor(model => model.Mask_Concat, Enumerable.Empty<SelectListItem>(), new { @class = "chosen-container chosen-container-multi", @style = "width:300px" })
@Html.ValidationMessageFor(model => model.Mask_Concat, "", new { @class = "text-danger" })
</div>
</div>
<input type="hidden" id="selectedMaskValues" name="selectedMaskValues" />
JS on view:
//join selected mask values
$("#Mask_Concat").chosen().change(function () {
var $hidden = $("#selectedMaskValues");
$hidden.val($(this).find('option:selected').map(function () {
return $(this).val();
}).get().join(","));
});
Controller:
public ActionResult Edit(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Chip_Master chipMaster = db.Chip_Master.Find(id);
if (chipMaster == null)
{
return HttpNotFound();
}
ViewBag.Manufacturer = new SelectList(db.Chip_Master, "Mask_Concat", "Mask_Concat", chipMaster.Mask_Concat.Split(',').ToList());
return View(chipMaster);
}
Database:
Mask_Concat Column: 1234,5678,2345,7890
Thoughts? Need more information?
See Question&Answers more detail:
os