2

I have got a simple form and it has got a MultiSelectList inside. This form method is GET. When I choose more items in SelectList and submit form, I want to see what I choose. I use SelectedValues for that. But it selects only first item in MultiSelectList.

My View :

<form method="get">
    @Html.DropDownList("kategori", new MultiSelectList(ViewBag.KategoriSelect, "id", "isim", ViewBag.KategoriSelected),
 new
 {
     @multiple = "true ",
     @size = "8"
 })

    <input type="submit" value="gönder" />
</form>

My Controller :

    public ActionResult Index(int[] kategori)
    {
        var db = new MyDbContext();

        var aracs = db.aracs.ToList();

        //items for multi select
        ViewBag.KategoriSelect = db.kategoris.ToList();

        //selected items
        ViewBag.KategoriSelected = kategori;

        return View(aracs);
    }

My Get URL : http://localhost:6151/?kategori=2&kategori=1&kategori=4&kategori=3

HTML output :
Html Output for multi select

But it must select all item. what must I do for that ?

Koopakiller
  • 2,838
  • 3
  • 32
  • 47
ASPMaker
  • 303
  • 5
  • 14

1 Answers1

0

I have worked on similar scenario where we use https://github.com/davidstutz/bootstrap-multiselect

Bootstrap Multiselect which can be loaded as list fro C# and converts to Multiselect with built in JS library.

CuriousRK
  • 69
  • 7