首页 > 代码库 > JQuery Plugin serials (1)--- Harvest Chosen
JQuery Plugin serials (1)--- Harvest Chosen
一、Download harvest chosen from github
https://github.com/harvesthq/chosen/
二、在页面引用
@using (Html.BeginForm()){ <fieldset> <legend>Multi-Select Demo</legend> <div class="editor-field"> @Html.ListBox("Countries", ViewBag.Countrieslist as MultiSelectList , new { @class = "chzn-select", data_placeholder = "Choose Countries..." }) <p> <input type="submit" value=http://www.mamicode.com/"Save" /> </p> </div> </fieldset>}<script src=http://www.mamicode.com/"@Url.Content("~/Scripts/chosen.jquery.js")"></script><link href=http://www.mamicode.com/"@Url.Content("~/Content/chosen.css")" rel="stylesheet" type="text/css" /><script> $(".chzn-select").chosen();</script>
三、Controller code
[HttpGet] public ActionResult MultiSelectCountries() { ViewBag.Countrieslist = GetCountries(new string[] { "1","2" }); return View(); } [HttpPost] public ActionResult MultiSelectCountries(FormCollection form) { ViewBag.YouSelected = form["Countries"]; string selected = form["Countries"]; ViewBag.Countrieslist = GetCountries(selected.Split(‘,‘)); return View(); } private MultiSelectList GetCountries(string[] selectedValues) { List<Country> countries = new List<Country> { new Country() { Id = 1, Name= "United States" }, new Country() { Id = 2, Name= "Canada" }, new Country() { Id = 3, Name= "UK" }, new Country() { Id = 4, Name= "China" }, new Country() { Id = 5, Name= "Japan" } }; return new MultiSelectList(countries, "Id", "Name", selectedValues); }
JQuery Plugin serials (1)--- Harvest Chosen
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。