jitendra

jitendra

  • 1.3k
  • 430
  • 67.5k

How to Bind Dropdownl list from database in mvc3

Sep 6 2013 1:54 PM
Code - Razor Code
  <div class="editor-field">
            @Html.DropDownList("CountryID", String.Empty)
            @Html.ValidationMessageFor(model => model.CountryID)
        </div>

Controller code
at the time on showing data in drop down list
 ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "Name");

at the time of showing data on saving time
ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "Name", state.CountryID);

plz send your comment - how many types we have bind data in drop downlist

How many type's I have bind dropdown list

plz give the exxamples