We have a controller, CountryController with an action “Add”, and the related View “Add”, and we have a SQL Server table named “Countries” with an int “Id” field and a string “CountryName” field.
I get all database data from DbContext and EntityFramework 6, so all the tables are mapped in the context.
In our CountriesModel we have:
- // within the model
- public SelectedList Countries {get; set;}
- // within the controller
- model.Countries = new SelectList(context.Countries.ToList(), "Id", “CountryName");
In the view Add we have:
- @model CountriesModel
- ….
- @Html.DropDownListFor(model=>model.Countries.SelectedValue, Model.Countries)

Join the conversation! Your thoughts help the community grow.