jQuery MultiSelect dropdownlist how to access results?

后端 未结 3 963
陌清茗
陌清茗 2021-01-07 01:06

How can I get the results from a JQUery Multi-select dropdownlist as called per an mvc3/razor?

http://abeautifulsite.net/blog/2008/04/jquery-multiselect/

3条回答
  •  不思量自难忘°
    2021-01-07 01:54

    Actually, you can also recieve the selected values by adding a parameter to your action.

    For instance, lets say you have following listbox:

    //Controller GET
    public ActionResult ManageUsers()
    {
        ViewBag.Users = new SelectList(repository.GetAllUsers(), "Id", "Email");
        return View();
    }
    
    //View
    @Html.ListBox(ViewBag.Users as SelectList, new { @id = "users" })
    
    //Controller POST
    [HttpPost]
    public ActionResult ManageUsers(List users)
    {
        //Manage all the selected users which will appear in the List.
    
        return View()...
    }
    

    I believe you can have an array as type instead of a generic list aswell, havn't tried it myself though, the key however is to name the parameter the same as the html element id for the listbox.

提交回复
热议问题