Chosen jQuery plugin with MVC 5

Chosen is a jQuery plugin that makes long, unwieldy select boxes much more user-friendly.

Model:

 public class CustomerCategoryOption
    {
        public int ID { get; set; }
        public string CategoryName { get; set; }
    }

controller:

    public ActionResult Index()
        {
            List customerCategoryOption = new List() { 
              new CustomerCategoryOption{ID=1, CategoryName = "PLATINUM"},
              new CustomerCategoryOption{ID=2, CategoryName = "SILVER"},
              new CustomerCategoryOption{ID=3, CategoryName = "GOLD"},
              new CustomerCategoryOption{ID=4, CategoryName = "ABC"},
              new CustomerCategoryOption{ID=5, CategoryName = "ABD"},
              new CustomerCategoryOption{ID=6, CategoryName = "ABM"},
            };

            ViewBag.CustomerCategory = new SelectList(customerCategoryOption, "ID", "CategoryName");

            return View();
        }

view:


@{
  ViewBag.Title = "Index";
}http://@Url.Content(http://@Url.Content(

@ViewBag.Message

@Html.DropDownList(“ID”, (IEnumerable)ViewBag.CustomerCategory, new { @class = “chosen” })

//

Result:
def

Ref Link:
http://harvesthq.github.io/chosen/
http://utsavized.com/chosen-multiselect-dropdown-list-with-asp-net-mvc3/

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: