Monday 11 January 2016

How to call async function inside Web form/ MVC Razor Asp.net?

How to call async function inside Web form/ MVC Razor Asp.net?

protected async void Page_Load(object sender, EventArgs e)
{
   Response.Write(await FunctionStringAsync("name"));
}
Above one is Working for me but, I want to use inside Razor like

<%=(await FunctionStringAsync("name"))%>
or
@(await FunctionStringAsync("name"))
I am getting

warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

error CS4033: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.