Bohn
Bohn

Reputation: 26919

Using Razor DropDownList helper to create a dropdown

I am just tasked to create the UI part for now. So I have something like:

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        @Html.Label("Default Group")
                        @Html.DropDownList("whatthe")
                    </div>
                </div>

Currently no body has written any Model or anything for these views yet. But this crashes on DropDownList for me, other simpler controls like CheckBox worked fine. How can I get it to show up until later that we add a model? The crash error

"There is no ViewData item of type 'IEnumerable' that has the key"

I looked it up, there is a topic for it, but my question is just how can I get it to show up for now until later that we add model,etc...

Upvotes: 1

Views: 64

Answers (2)

Mark Evaul
Mark Evaul

Reputation: 653

Specify the list of select items on the method.

@Html.DropDownList("whatthe", new List<SelectListItem>())

Upvotes: 2

Mark Evaul
Mark Evaul

Reputation: 653

You can just put in regular markup.

<select name="whatthe"></select>

You'll also need to add in some options to give it some width unless you style it with css.

Upvotes: 0

Related Questions