【发布时间】:2021-08-16 12:00:42
【问题描述】:
所以,我在 Blazor Server 中有一个应用程序,我有两个页面。在第一页上,用户介绍了他的用户名,在他单击登录按钮后,我想在第二页上显示他介绍的用户名。我尝试使用路由参数,但我不知道这是否正确,因为我是 Blazor 新手。
@page "/firstPage"
<EditForm Model="@user" OnValidSubmit="@Login">
<label class="form-control-label text-muted">Username</label> <input type="text" id="username" name="username" @bind="user.Username">
<button class="btn-block btn-color">Login</button>
</EditForm>
@page "/secondPage"
//here I want to show the username from the first page
【问题讨论】:
-
有很多选择,但我建议阅读 .net 中的 TempData。
-
您是否使用 ASP.NET Core Identity 的内置身份验证?用户详细信息存储在哪里?在 EF Core 托管数据库中?
-
@AmalK 不,我没有使用内置身份验证,我使用的是自定义身份验证,是的,我有一个用户类和一个存储数据的 EF Core 托管数据库跨度>
-
如果你只想传递用户名,可以在url中作为参数传递,参考this。
标签: c# asp.net-core blazor