blazor - 从 Blazor 客户端访问 IdentityUser
问题描述
我目前正在使用 Blazor WebAssembly、ASP.NET Core 托管、EF/Identity Core。
我想在我的客户端 Blazor 页面中填写国家和另一位用户的下拉列表。
Country
很简单,因为它的模型在\Shared\Models\Country.cs
.
我很难携带UserIdentity
,因为它是 Microsoft Identity 的一部分,我无法放入我的\Shared\Models
. 所以,编译器不能识别实体,我不能带它的命名空间。
关于如何填充用户下拉列表的任何想法?也许创建一个名为\Shared\Models\AppUser.cs
继承自的虚拟类UserIdentity
就足够了?
或者也许添加对服务器项目的引用?
这是示例代码:
@page "/"
@using BlazorApp.Shared.Models
@inject HttpClient Http
<h1>Dropdown Example</h1>
@if (countryList == null || userList == null )
{
<p><em>Loading...</em></p>
}
else
{
<select class="form-control">
<option value="">-- Select Country --</option>
@foreach (var country in countryList)
{
<option value="@country.Id">@country.CountryName</option>
}
</select>
<select class="form-control">
<option value="">-- Select User --</option>
@if (userList != null)
{
@foreach (var user in userList)
{
<option value="@user.Id">@user.UserName</option>
}
}
</select>
}
@functions {
List<Country> countryList = new List<Country>();
List<IdentityUser> userList = new List<IdentityUser>();
protected override async Task OnInitAsync() {
countryList = await Http.GetJsonAsync<List<Country>>("api/country/GetCountryList");
userList = await Http.GetJsonAsync<List<IdentityUser>>("api/user/GetUserList");
}
}
解决方案
推荐阅读
- java - 如何转换列表
从 vertx 到 String Array 以用于笛卡尔积 - node.js - Docker 上的 NodeJS 脚本:/lib64/libz.so.1:未找到版本“ZLIB_1.2.9”
- python - 如何在用于提取 Twitter 推文的 python 脚本中解决此错误
- sql - 为什么 dbms_random.value 在图形查询(连接方式)中返回相同的值?
- javascript - 向我的 javascript 滑块添加箭头
- javascript - JSON 按键值分组到新的 JSON Javascript
- java - Java XML Parsing - 使用重复节点解析 XML
- c - 在C中的函数内部声明函数
- postgresql - 无法删除数据库——访问数据库的用户数量的证据相互矛盾
- ios - iOS Swift 4 中的 Alamofire 发布方法?