0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Blazor网页页面跳转

Posted at

Blazor制作网页的时候,会有点击按钮然后跳转到另一个页面的操作
这个时候,可以使用NavigationManager.NavigateTo语句来执行跳转程序
具体代码如下

@inject NavigationManager NavigationManager //跳转页面用
@rendermode InteractiveServer //按钮动作用

<button class="btn btn-primary" @onclick="jumpPage">跳转按钮</button>

@code {
    
    //跳转页面
    private void jumpPage() => NavigationManager.NavigateTo("/跳转页面的@page后面的名称");
}

注意:
@inject NavigationManager NavigationManager 是跳转页面的指令所需要的运行库,如果不导入这个库,则没有办法执行 NavigationManager.NavigateTo 指令
@rendermode InteractiveServer 是按钮动作所需要的运行库,如果不导入这个库,则会出现点击按钮但是程序捕获不到的问题(即使在@code里面打断点,也无法进入断点)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?