How to use multiple select in mvc 4?

前端 未结 2 1027
野趣味
野趣味 2021-02-12 18:10

I want to use multiple select in Chosen. I have Skill model like,

public class Skill 
    {
        public int Id { get; set; }
        public string Name { ge         


        
2条回答
  •  野的像风
    2021-02-12 18:47

    The only difference I can see between the hardcoded example (which you stated that is working) and the one you generate with the ListBox helper is the absence of the data-placeholder attribute. So:

    @Html.ListBox(
        "Countries", 
        ViewBag.Skills as MultiSelectList,
        new { @class = "chzn-select", data_placeholder = "Choose a Country..." } 
    )
    

    This should at least generate the same markup as what you said is working. If it doesn't work then probably you haven't setup the plugin correctly or you have some other javascript errors. Read the documentation of the plugin about how it should be setup.

提交回复
热议问题