jQuery dropdownlist MVC basic setup - maikelbos0/VDT GitHub Wiki

Include the jQuery-dropdownlist.MVC package in your project and make sure to include references to the jQuery-dropdownlist files in your pages (see jQuery-dropdownlist basic setup). Then add a property of type vdt.jquerydropdownlist.MVC.JQueryDropdownlist to your viewmodel.

using vdt.jquerydropdownlist.MVC;

public class ExampleViewModel {
    public JQueryDropdownlist DemoProperty { get; set; }
}

In your controller action, set the desired properties of the dropdownlist, including the items that will appear and the selected items if required.

public ActionResult Index() {
    return View(new ExampleViewModel() {
        DemoProperty = new JQueryDropdownlist() {
            Items = new[] {
                new JQueryDropdownlistItem() { Value = "1a", Text = "Option 1a" },
                new JQueryDropdownlistItem() { Value = "1b", Text = "Option 1b" },
                new JQueryDropdownlistItem() { Value = "2", Text = "Choice 2" },
                new JQueryDropdownlistItem() { Value = "3", Text = "Third choice" }
            },
            SelectedValues = new[] { "1b", "2" },
            IsMultiselect = true
        }
    });
}

In your view, use the HTML helper extensions to render the dropdownlist.

@using vdt.jquerydropdownlist.MVC

@Html.JQueryDropdownlistFor(model => model.DemoProperty)