您好,如何Blazor使用参数重定向到另一个页面?
@page "/auth"
@using Microsoft.AspNetCore.Blazor.Services;
@inject AuthService auth
@inject IUriHelper urihelper;
<input type="text" bind="@Username" />
<button onclick="@AuthAsync">Authenticate</button>
@functions{
public string Username { get; set; }
public string url = "/home";
public async Task AuthAsync()
{
var ticket=await this.auth.AuthenticateAsync(Username);
urihelper.NavigateTo(url); //i see no overload that accepts parameters
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我想导航到/home页面并为其提供一个字符串作为参数。
做这个:
@page "/home"
@page "/home/{username}"
<h1>@Username is authenticated!</h1>
@functions {
// Define a property to contain the parameter passed from the auth page
[Parameter]
private string Username { get; set; };
}
Run Code Online (Sandbox Code Playgroud)
@page "/home"
@page "/home/{username}"
<h1>@Username is authenticated!</h1>
@functions {
// Define a property to contain the parameter passed from the auth page
[Parameter]
private string Username { get; set; };
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助...
| 归档时间: |
|
| 查看次数: |
3488 次 |
| 最近记录: |