Populate dropdown list from a DB table (ASP.NET CORE MVC)
Hello Redditers,
I'm Working on a web application project using ASP.NET Core MVC and EF.
I have a model script for a Address that has a property called "Country" of type string, There is a "Create" view where the user can create addresses and store them in the database, I need the page to have a dropdown list that has all the countries and the user can choose from them instead of having to type the country, and I need the items in that dropdown list to be retrieved from the DB
so I have a model script called "CountryModel" that has 2 properties: ID, CountryName.
I've been scratching my head over how to create a dropdown list in the Create view and have it retrieve data from a table in the database, and then have the selected value be saved in another model (Address model) as a string within the same view.
any thoughts ?
Thank you.
0 comments:
Post a Comment