In this article I will explain with an example, how to populate (bind) DropDownList from database using Entity Framework in ASP.Net Core MVC.
This article will also explain how to add Default Item (Blank Item) to DropDownList at First position when populating from database using Entity Framework in ASP.Net Core MVC.
I have made use of the following table Customers with the schema as follows. CustomerId is an Auto-Increment (Identity) column.
ASP.Net Core MVC: Populate (Bind) DropDownList from database using Entity Framework
I have already inserted few records in the table.
ASP.Net Core MVC: Populate (Bind) DropDownList from database using Entity Framework
Note: You can download the database table SQL by clicking the download link below.
          Download SQL file
The Model class consists of the following two properties.
Note: In this article, only two Columns will be used and hence two properties are added to the class.
public class Customer
    public int CustomerId { get; set; }
    public string Name { get; set; }
Database Context
Once the Entity Framework is configured and connected to the database table, the Database Context will look as shown below.
Note: For beginners in ASP.Net Core and Entity Framework, please refer my article ASP.Net Core: Simple Entity Framework Tutorial with example. It covers all the information needed for connecting and configuring Entity Framework with ASP.Net Core.
using DropDownList_EF_Core.Models;
using Microsoft.EntityFrameworkCore;
namespace DropDownList_EF_Core
    public class DBCtx : DbContext
        public DBCtx(DbContextOptions<DBCtx> options) : base(options)
        public DbSet<Customer> Customers { get; set; }
The Controller consists of the following two Action methods.
Action method for handling GET operation
Inside this Action method, the records are fetched from the Customers table using Entity Framework and are copied to SelectList class object which is used for populating DropDownList in .Net Core.
Finally, the SelectList class object is sent to the View.
Action method for handling POST operation
This Action method handles the call made from the POST function from the View.
When the Form is submitted, the Text and Value of the selected DropDownList Item are captured through the two parameters i.e. customerId and customerName.
The values of CustomerId and CustomerName are fetched and are set into a ViewBag object which will be later displayed in View using JavaScript Alert Message Box.
public class HomeController : Controller
    private DBCtx Context { get; }
    public HomeController(DBCtx _context)
        this.Context = _context;
    public IActionResult Index()
        SelectList customers = new SelectList(this.Context.Customers.ToList(), "CustomerId", "Name");
        return View(customers);
    public IActionResult Index(string customerId, string customerName)
        ViewBag.Message = "Name: " + customerName;
        ViewBag.Message += "\\nID: " + customerId;
        return View();
The following View consists of an HTML Form with following ASP.Net Tag Helpers attributes.
asp-action – Name of the Action. In this case the name is Index.
asp-controller – Name of the Controller. In this case the name is Home.
method – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.
The Form consists of a DropDownList, a Hidden Field and a Submit Button.
The Model data has been assigned to the DropDownList using the asp-items Tag Helpers attribute.
The DropDownList has been assigned a jQuery OnChange event handler, when an item is selected in the DropDownList, the Text of the selected item is copied in the Hidden Field.
When the Submit Button is clicked, the Form gets submitted and the CustomerId and CustomerName values are sent to the Controller.
Finally, the CustomerId and CustomerName values of the selected Customer are displayed using JavaScript Alert Message Box.
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@model SelectList
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <form method="post" asp-controller="Home" asp-action="Index">
        <select id="ddlCustomers" name="CustomerId" asp-items="Model">
            <option value="0">--Select Customer--</option>
        <input type="hidden" name="CustomerName" />
        <input type="submit" value="Submit" />
        <script type="text/javascript" src=""></script>
        <script type="text/javascript">
            $("body").on("change", "#ddlCustomers", function () {
        @if (ViewBag.Message != null)
            <script type="text/javascript">
                $(function () {
ASP.Net Core MVC: Populate (Bind) DropDownList from database using Entity Framework