To create asynchronous controller, follow almost same steps as we have followed while creating a controller for a Model.
Clicking Add button, opens up another dialog box. Select appropriate Model class.
Select “User async controller actions” checkbox (it is important as this is what creates the Asynchronous controller, otherwise it creates normal controller.). Now give the Controller name as we wish. No need to suffix with “Async” word. We have done it just to differentiate with other controller of the same Model in this project.
A sample asynchronous action method
public async Task<ActionResult> Index() { return View(await db.PersonalDetails.ToListAsync()); }
Now, if we try to differentiate between the normal controller and asynchronous controller action methods, following things differs
async
keyword that notifies that this action method returns data asynchronously.ToList()
method we are using ToListAsync()
method that returns the data asynchronously.