Bind Html.DropDownList with static items

Mukesh picture Mukesh · Apr 7, 2011 · Viewed 91.2k times · Source

I have to bind an Html.DropDownList with just two items statically.

Text="Yes" Value="1"
Text="No"  Value="0"

The important thing is that, I have to set the text and value fields.

How can I do this?

Answer

Saurabhbhatt picture Saurabhbhatt · Nov 11, 2012

I used this is properly working

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

                 {
                    new SelectListItem{ Text="Active", Value = "1" },
                    new SelectListItem{ Text="Not-Active", Value = "0" }
                 })