Hi @李畋岷 ,
How to call web api, such as Window.alert and FileReader, in Razor components using c# instead of js?
To the Window.Alert, if you want to show the alert, confirm or prompt dialog in Asp.net core Blazor application, you need to use the JSRuntime instance.
Refer to the following sample code:
The result is like this:
More detail information, refer to Call JavaScript functions from .NET methods in ASP.NET Core Blazor.
For the FileReader, if you want to upload file in Asp.net core Blazor application, you can use the InputFile component to read browser file data into .NET code, see ASP.NET Core Blazor file uploads.
Further, is it possible to thoroughly use c # instead of js in Blazor projects?
Not sure which effect you want to achieve, but you can check the ASP.NET Core Blazor event handling, if using the event handling can achieve the same behavior, then there is no need to use JS.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion