Translate

Wednesday, 25 November 2015

Static and Dynamic Droprdownlists in MVC

Here How to bind Dropdown in Static and Dynamically.


Static DropDownList:
  
            @Html.DropDownListFor(m=>m.CountryName,new List<SelectListItem>{
                    new SelectListItem{ Text="India", Value = "1" },
                    new SelectListItem{ Text="US", Value = "0" },
new SelectListItem{ Text="UK", Value = "2" }
                 })

Dynamic DropDownList:

  @Html.DropDownListFor(m=>m.CountryName,new SelectList((System.Collections.IEnumerable)ViewData["country"],"value","text"),"Select")