我遵循了Rick Anderson的例子,但是我無法使其工作。我有原始的多選框,但沒有收穫選擇多選。mvc harvest選中多選下拉列表
查看:
@Html.ListBox("Clearances", ViewBag.Clearanceslist as MultiSelectList, new { htmlAttributes = new { @class = "form-control chosen-select", style="width:350px;" } })
視野下的是我的javascript:
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$('.datepicker').datepicker();
$(".chosen-select").chosen();
</script>
}
這是我列入BundleConfig.cs腳本:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/chosen.jquery.js"
));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/bootstrap-datepicker.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/datepicker.css",
"~/Content/chosen.css",
"~/Content/site.css"));
}
控制器:
private MultiSelectList GetClearances(string[] selectedValues)
{
return new MultiSelectList(db.Clearances.Where(c => c.Active == true), "ClearanceID", "ClearanceName", selectedValues);
}
// GET: CardKeys/Create
public ActionResult Create()
{
ViewBag.Clearanceslist = GetClearances(null);
return View();
}
我還想念什麼?
您是否包含相關腳本?您在瀏覽器控制檯中收到哪些錯誤消息? (以及指向你的「示例」的鏈接可能有助於理解你想要做什麼) –
我已經包含了所有相關的腳本(我相信)。我沒有收到任何錯誤消息。 – Meidi