问题描述:如何在 Blazor WASM 中使用 POST 请求跳转到 index.html 页面?
解决方案:通过使用 HttpClient 类和 NavigationManager 类,在 Blazor WASM 中实现 POST 请求跳转到 index.html 页面。
以下是实现的代码示例:
@page "/post"
@inject NavigationManager NavigationManager
@inject HttpClient Http
POST Request to index.html
@code {
}
@code {
private async Task SubmitForm()
{
var formData = new Dictionary
{
{ "param1", "someValue" }
};
var response = await Http.PostAsync("index.html", new FormUrlEncodedContent(formData));
NavigationManager.NavigateTo(response.RequestMessage.RequestUri.ToString(), forceLoad: true);
}
}
这样,我们就可以实现在 Blazor WASM 中使用 POST 请求跳转到 index.html 页面。