Use of await in Razor views

前端 未结 8 894
面向向阳花
面向向阳花 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条回答
  •  萌比男神i
    2020-11-28 12:53

    You can await calls in razor pages? I have a Blazor app and most of my methods are async:

    Razor page:

    
    

    This is a MatBlazor FloatingActionButton which calls the life time cycle event OnInitializedAsync()

    C# Code:

    protected override async Task OnInitializedAsync()
    {
        // Do something like get data when the form loads
    }
    

提交回复
热议问题