0
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'.

Raj kumar
  • 1,275
  • 15
  • 20
  • 1
    You can't, and you shouldn't want to. Ensure that your view model contains all data that you wish to display. – CodeCaster Jan 11 '16 at 11:07
  • Dear @CodeCaster, Why not? Is it documented anywhere? As i think if we can explicitly mark page_load as async then why not control rendering? Using client script and achieve target by loading once inside controller or page_load is different thing. In my case i am using multiple if else in side razor and create tags dynamically, I don't want to repeat if else inside controller and razor again. – Raj kumar Jan 13 '16 at 10:35
  • You cannot mark a view async, period. Razor gets compiled to a C# class that is executed, and async is not supported in it. You should not even want to use async in a view. If you need it, it's a sign that you're doing too much heavy work in the view. – CodeCaster Jan 13 '16 at 10:55

0 Answers0