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;
}