1

I have the below action in MVC3 Application(empty application in VS2012) which just loads a Index page with just one H2 element. Granted this does not do anything but I am just learning the async and await functionality.

The index page does not load up. I just get this in the browser.

System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult]

Also in fiddler i get the request in blue color.What Am i Doing wrong. Why is the view not showing up.

The asynchronous call does succeed and shows the html contents in the website.

View Code:

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>


public async Task<ActionResult> Index()
        {
            Task<string> getContentsTask = GetContentsAsync();
            Thread.Sleep(10000);
            string contents = await getContentsTask;
            return View("Index");
        }

        async Task<string> GetContentsAsync()
        {

            HttpClient client = new HttpClient();
            Task<string> contents = client.GetStringAsync("http://www.msdn.com");

            string data = await contents;
            return data;
        }
4
  • What version of MVC are you using? Commented Sep 30, 2013 at 16:05
  • Its mentioned in the question itself MVC4 though i dont use the webapi. Commented Sep 30, 2013 at 16:05
  • 1
    Are you sure? This would happen if you use an MVC version that does not recognize async. Commented Sep 30, 2013 at 16:18
  • @SLaks: Really Really sorry the app was an MVC3 one. I created one MVC4 and it worked fine. Thank you so much> Stupid accidental mistake on my side. Commented Sep 30, 2013 at 16:33

1 Answer 1

5

MVC3 does not recognize Tasks.

Upgrade to MVC4.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.