Creating a DropdownList [closed]

0

I'm using asp.net-mvc-5, and wanted to know how to create a DropdownList without being in this pattern here:

        <div id="conteudoEscolha">
            @Html.DropDownList("", null, htmlAttributes: new { @class = "form-control", id = "Musico" })
        </div>

I mean, I do not want to use @ html.DropDownList, as I'll feed it using javascript. I may be wrong, but the way I did it up is giving error when I enter the screen

Ididasstatedby@MarcoViniciusandthendisplayedthelinkbelow:

    
asked by anonymous 21.11.2016 / 18:17

1 answer

1

You can not pass null

pass

new List<SelectListItem>()

@Html.DropDownList("batata", new List<SelectListItem>(), htmlAttributes: new { @class = "form-control", id = "Musico" })

If you want you can instantiate in your controler this way

var selectList = new List<SelectListItem>();
selectList.Add(new SelectListItem{Text = "Selecione", Value = ""});

ViewBag.SelectList = selectList;

and the view would look like

@Html.DropDownList("batata",  (List<SelectListItem>)ViewBag.SelectList, htmlAttributes: new { @class = "form-control", id = "Musico" })
    
21.11.2016 / 19:28