0
votes

I have a simple dropdown list on an asp.net page. The data that populates the dropdown is slow to load and there isn't much I can do about it.

Instead of waiting for the data to populate and then display the page once fully loaded, I would like to display the page and maybe have a Loading... show up on the dropdown list while it loads.

What is the correct way of achieving that?

1
look into the await and async keywords on methods. - Marshall Tigerus
Lots of data will take lots of time. async/await won't make that go faster, they'll release the thread while waiting for the data to load. Just don't load data that you won't display. Use paging and/or load the data from JavaScript in pages - Panagiotis Kanavos
do ajax call from page to server to fill dropdown - tym32167
It is not a huge amount of data, more like the TFS API I am using seems to be slow. - sd_dracula
Better yet, don't fill the combo at all. If it takes so long to load, how are users going to work with it? Consider a solution that searches for matches as you type - Panagiotis Kanavos

1 Answers

0
votes

Preform an ajax request to your controller to a specific action result that just returns the data you need to populate the dropdown. Example:

$(function() { $.ajax({ url: 'controller/action/', data: { arg1: 1, arg2: 2 }, success: function (data) { //handle the data } }); }); `

public ActionResult SendDropdown(int arg1, int arg2) {
    //code to get the dropdown data
    return Json(new { dropdowndata }, JsonRequestBehaviour.AllowGet);
}

`