我正在使用最新的MVC5。 我想使用ListBox而不是DropDown。控制使用的決定不是單一/多重選擇決定。ListBoxFor在asp.net中單擊選擇mvc
那是錯誤,我得到:
An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code
Additional information: The parameter 'expression' must evaluate to an IEnumerable when multiple selection is allowed.
@using (Html.BeginForm())
{
// @Html.ValidationMessageFor(model => model.)
@Html.ListBoxFor(x => x.SelectedCompanyId, new SelectList(Model.Companies, "CompanyId", "Address"), new { @id = "CompanyListBox" })
}
但我怎麼能刪除多重選擇? jQuery的不幫助這裏的剃鬚刀例外首次提出之前準備好文檔:
$(document).ready(function() {
debugger;
$("#CompanyListBox").removeAttr('multiple');
});
工作感謝! – HelloWorld