16 June, 2021
0 Comments
1 category
If you need to call an async C# service method from an ASP .NET razor page, you can use the System.Threading.Tasks.Task.Run method.
Assuming we have a C# service class “MyService.cs” and this service contains an async method called “GetMyData”, then you can call it in a razor page like so:
@{
var myService = new MyService();
var myData = System.Threading.Tasks.Task.Run(() => myService.GetMyData()).GetAwaiter().GetResult();
}
Category: Uncategorized