Home > MVC > ASP.NET Core Populate Dropdownlist from Database



ASP.NET Core Populate Dropdownlist from Database

In this article, we will explain how to Populate Dropdownlist from Database in ASP.NET Core with an example and sample code.


In this article, we will explain how to Populate Dropdownlist from Database in ASP.NET Core with an example and sample code. We have used the razor view engine and bound the Dropdownlist from the database using ADO.net. It's a very simple way of binding Dropdownlist. In this example, we have taken employee's and customer's data for binding a Dropdownlist. You can see the example code below. Visual Studio Code is a lightweight but powerful source code editor. It is a fully open-source and cross-platform framework available on Windows, Linux, and Mac.

 

Step -1

Open Visual Studio Code.

ASP.NET Core  Populate Dropdownlist from Database

 

Step -2

Click on the file in the menu and select Open Folder. We are creating a folder for project(SampleCode) and select created folder name.

ASP.NET Core  Populate Dropdownlist from Database

 

Step -3

Go to Terminal and Select New Terminal in the menu. In the terminal window, type dotnet new mvc .

ASP.NET Core  Populate Dropdownlist from Database

 

Step -4

Build and Run the MVC Application. In the terminal window, type dotnet Build and dotnet run .

ASP.NET Core  Populate Dropdownlist from Database

 

Required Namespaces

We will need to use the following namespaces.

 

Views

We have provided razor view html below.

 

Models

In this model we have two child class for dropdownlist binding. you can use your existing class for this activity.

 

HomeController

 

Output

ASP.NET Core  Populate Dropdownlist from Database

 

Download




Note: All contents are copyright of their authors.



Comments



Leave a Reply

Comment:*
Email ID:*


Name:*