Use of await in Razor views

前端 未结 8 880
面向向阳花
面向向阳花 2020-11-28 12:48

Is it possible to await on tasks in Razor .cshtml views?

By default it complains that it can only be used in methods marked with async so I

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 13:14

    Following on MaxP's answer, it's easy to return a value from that code, despite Knagis comment:

    @{
        int x = DoAsyncStuffWrapper().Result;
    }
    @functions {
        async TaskDoAsyncStuffWrapper() 
        {
            await DoAsyncStuff();
        }
    }
    

提交回复
热议问题