ShaneKm
ShaneKm

Reputation: 21338

MVC Task Controller

I need to run async Task Action in a MVC4 controller. In some articles it is stated that my controller needs to inherit AsyncController, and in some it does not.

for example in this sample:

http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4 it's not.

  1. Which is it?. In order to run async controller Actions, is it necessary for my controller to inherit "AsyncController"??

Upvotes: 2

Views: 278

Answers (1)

Narendra V
Narendra V

Reputation: 605

You dont need inherit from async controller for asynschrnous actions. Below is the example.

public class HomeController : Controller
{
    public async Task<ActionResult> Index()
    {
         DataServiceClient client = new DataServiceClient();
         var cities = await client.GetCitiesAsync();
        return View(cities);
     }
}

Upvotes: 3

Related Questions