码迷,mamicode.com
首页 > Web开发 > 详细

JQuery Plugin serials (1)--- Harvest Chosen

时间:2014-08-22 19:23:49      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   art   

一、Download harvest chosen from github

https://github.com/harvesthq/chosen/

二、在页面引用

bubuko.com,布布扣
@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="Save" />
            </p>

        </div>
    </fieldset>
}
<script src="@Url.Content("~/Scripts/chosen.jquery.js")"></script>
<link href="@Url.Content("~/Content/chosen.css")" rel="stylesheet" type="text/css" />

<script>
    $(".chzn-select").chosen();
</script>
View Code


三、Controller code

 

bubuko.com,布布扣
 [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);
        }
View Code

 

JQuery Plugin serials (1)--- Harvest Chosen

标签:style   blog   http   color   os   io   for   ar   art   

原文地址:http://www.cnblogs.com/Luxuan/p/3929978.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!