Change your ViewModel as follows
public class RegisterViewModel {
and in your GET action method, set Get Data from your database and set the Continents Collection property of your ViewModel
public ActionResult DoThatStep() { var vm=new RegisterViewModel(); //The below code is hardcoded for demo. you may replace with DB data. vm.Continents= new[] { new SelectListItem { Value = "1", Text = "Prodcer A" }, new SelectListItem { Value = "2", Text = "Prodcer B" }, new SelectListItem { Value = "3", Text = "Prodcer C" } }; return View(vm); }
and in View ( DoThatStep.cshtml ) use
@model RegisterViewModel @using(Html.BeginForm()) { @Html.ValidationSummary() @Html.DropDownListFor(m => m.SelectedContinent, new SelectList(Model.Continents, "Value", "Text"), "Select") <input type="submit" /> }
Now this will make your Requested Drop field.
Shyju
source share