来自 Identity 的 FullName 无法正常工作 asp .net core 3.0

奥马克

我正在处理一个小项目并尝试显示全名(我在从 IdentityUser 继承的 ApplicationUser 模型中添加的)和模型下方:

public class ApplicationUser : IdentityUser 
{
    public int PersonnalNumber { get; set; }
    public string FullName { get; set; }
}

这是 SystemDetails 模型与应用程序用户的关系:

public class SystemDetails
{
    [Key]
    public int Id { get; set; }

    [Required]
    [Display(Name = "System Name")]
    public string SystemName { get; set; }
    [Required]
    [Display(Name = "Admin Name")]
    public string SystemAdminId { get; set; }
    public string ServerNames { get; set; }

    [ForeignKey("SystemAdminId")]
    public virtual ApplicationUser ApplicationUser { get; set; }
}

这是索引视图:

@if (Model.Count() > 0)
    {
        <table class=" table table-striped border">
            <tr class="table-secondary">

                <th>
                    @Html.DisplayNameFor(m => m.SystemName)
                </th>
                <th>
                    @Html.DisplayNameFor(m => m.SystemAdminId)
                </th>

                <th></th>
                <th></th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(m => item.SystemName)
                    </td>

                    <td>
                        @Html.DisplayFor(m => item.ApplicationUser.FullName)
                    </td>


                    <td>
                        <partial name="_TableButtonPartial" model="@item.Id" />
                    </td>
                </tr>
            }

一切正常,除了 FullName 未显示在索引页面上,我可以显示 SystemAdminId,这是注册用户 ID,但是当我尝试使用 Applicationuser.FullName 显示 FullName 时,它​​没有显示任何内容!当我在 SystemDetails Controller 上创建记录时,它被正确保存在数据库中,如下所示:

系统管理员 ID

这是创建操作:

[HttpPost,ActionName("Create")]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> CreatePost()
    {
        List<ApplicationUser> userList = new List<ApplicationUser>();


        if (!ModelState.IsValid)
        {
            return NotFound();
        }
        userList = await (from user in _db.ApplicationUser select user).ToListAsync();
        ViewBag.usersList = userList;


        _db.SystemDetails.Add(SystemDetails);
        await _db.SaveChangesAsync();
        return RedirectToAction(nameof(Index));
    }

感谢任何帮助

Nan Yu

在控制器中,当查询SystemDetails列表时,您应该加载相关的ApplicationUser

using Microsoft.EntityFrameworkCore;

var result = _dbContext.SystemDetails.Include(f => f.ApplicationUser).ToList();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ASP Net Core ConfirmEmail无法正常工作

使用ASP.NET Core Identity 3的用户角色权限

ASP.NET Core MVC Ajax无法正常工作

LINQ 查询无法正常工作 ASP.NET CORE MVC

ASP.Net Core CookieRequestCultureProvider无法正常工作

ASP.NET Core 5.0 RequestSizeLimit无法正常工作

Asp.net Core UseExceptionHandler无法正常工作POST请求

使用Visual Studio 2013模板和Asp.Net Identity进行代码优先无法正常工作?

ASP.NET Core 3:无法从根提供程序解析作用域服务'Microsoft.AspNetCore.Identity.UserManager`1 [Alpha.Models.Identity.User]'

将Asp.Net Core 1转换为Core 2后Jwt无法正常工作

ASP.NET Identity 与 ASP.NET Identity Core:与 Identity Server 等的区别和用法?

在Identity Asp.net core 3 MVC中创建服务IUserStore时出错

在Asp.Net Core 3 Identity中创建自定义SignInManager

Bootstrap Accordion 3.3.7在foreach循环中崩溃asp.net core 1.1无法正常工作

ASP.NET Core 3.0 MVC连接中的SignalR是否仍然无法正常工作?

属性路由在ASP.NET Core 3.0中无法正常工作

发布到Azure后ASP.NET Core应用无法正常工作

ASP.Net Core Server中的角度PWA-Serviceworker-Cache无法正常工作

ASP.NET Core和JQuery兼容AJAX无法正常工作

Angular4 Material主题在ASP.NET Core项目上无法正常工作

自托管ASP.NET Core 2.0:TagHelper无法正常工作

我添加的Asp.net Core 2.0 MVC CSS无法正常工作

将ASP.NET Core应用发布到Azure无法正常工作

ASP.NET Core自定义标签助手无法正常工作

Cookie 身份验证与 JWT 身份验证 ASP.NET CORE 无法正常工作

使用VSCode的Asp.Net Core本地化无法正常工作

ASP.NET CORE 3.0 应用到默认网站/MySite 下的 IIS 无法正常工作

在ASP.NET Core 3中使用来自单独类的Hub

.Net Core MemoryCache PostEvictionCallback无法正常工作