There are multiple ways to populate dropdowns in ASP.NET MVC. But using jQuery Ajax for populating a dropdown is easy and fast. So in this article I will show you how to populate a dropdown from the database using jQuery ajax.
I am assuming that you have a table in your database named "Department" and we will get data from that table.
First of all in a create a View of ay name (I am creating one with the name ViewProducts) and add the following code.
<form id="myForm">
<label for="departmentsDropdown"><b>Departments</b></label>
<select class="form-control" id="departmentsDropdown" name="departmentsDropdown"></select>
</form>
This is the html code for our dropdown. It is not populated yet so it will not have any data now. It will look like.

Now we have created our dropdown but it does not have any data yet. I will write a function (method) in the controller that will get data from the database for all departments from the "Department" table.
public ActionResult getDepartment()
{
DatabaseEntities db = new DatabaseEntities();
return Json(db.Departments.Select(x => new
{
DepartmentID = x.DepartmentID,
DepartmentName = x.DepartmentName
}).ToList(), JsonRequestBehavior.AllowGet);
}
This above function will get data from the database and send it back in JSON format. Now I will write a Javascript function that will pass an Ajax call to this above method and get data from it and then this data will be displayed in the dropdown.
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Users/getDepartment",
data: "{}",
success: function (data) {
var s = '<option value="-1">Please Select a Department</option>';
for (var i = 0; i < data.length; i++) {
s += '<option value="' + data[i].DepartmentID + '">' + data[i].DepartmentName + '</option>';
}
$("#departmentsDropdown").html(s);
}
});
});
This above Ajax call will call the method in the controller and get data from the controller and then this data will be displayed in the dropdown. After these steps, if I run my project, the dropdown will look like the following.

This is how we can populate a dropdown with an Ajax call in ASP.NET MVC.

michael azizPosted Jan 6, 2023, 10:17 PM
God bless you .. God send your post to me
michael azizPosted Jan 6, 2023, 10:17 PM
Thanks a lotttttttttttttttttttttttt
Kapil GuptaPosted Jun 24, 2021, 6:05 PM
Hi But after Population Dropdown with Ajax call, Select event of the dropdown lost. how we can fix that?
Wilson OseraPosted Jan 11, 2021, 12:30 AM
How to add Mutiselect function?
MOMODU SWARRAYPosted Jul 4, 2020, 1:43 PM
Thanks a lot. This is very helpful.
Jagdeep SinghPosted Dec 21, 2019, 4:32 AM
Thanks so much....
Bidyasagar MishraPosted Sep 15, 2019, 8:50 PM
How can i bind without using jquery , only using ajax
nazir aliPosted Aug 8, 2019, 8:13 AM
How i can populates dropdown list by ajax call if i am using html helper instead core html
nazir aliPosted Aug 8, 2019, 8:12 AM
How i can populate @html.dropdownlist() using ajax is i am using html helper?
Keith EPosted Aug 26, 2018, 1:14 PM
Great article, simple but very informative. One question I have been trying to figure out is for my Edit form, I want a value selected if the Model has a value selected. How would I do this? Thanks...
Rajesh KumarPosted Aug 1, 2018, 11:52 PM
Very nice article..............
Viknaraj ManogararajahPosted Jul 14, 2018, 10:50 PM
Nice Article, Thank you for sharing.........
Hadshana KamalanathanPosted Jul 14, 2018, 7:17 PM
Thanks for sharing
K FrankPosted Jul 12, 2018, 5:48 AM
This is nice and great. Just as I wanted
Karthik ChintalaPosted Jul 12, 2018, 1:37 AM
Good One. Thanks for sharing
Mohamed IbrahimPosted Jul 11, 2018, 4:31 PM
Thanx for sharing