Asp.net mvc 5 将用户数据输出到视图MVC5

Asp.net mvc 5 将用户数据输出到视图MVC5,asp.net-mvc-5,asp.net-identity,Asp.net Mvc 5,Asp.net Identity,我仍在学习MVC5,在如何从用户表输出数据方面遇到了一些问题。我在注册表中添加了一些字段,这些字段包含电话号码和驾照号码,我可以成功地将数据发送到数据库,但检索数据并在登录用户视图中显示数据时遇到问题。我已经看了一些例子,但我肯定遗漏了一些东西,因为我可以输出一些数据,但不能输出我特别想要的字段。(电话号码和驾驶执照号码) 这是我的密码 Index.cshtml User Data: @{ System.Security.Claims.ClaimsPrincipa

我仍在学习MVC5,在如何从用户表输出数据方面遇到了一些问题。我在注册表中添加了一些字段,这些字段包含电话号码和驾照号码,我可以成功地将数据发送到数据库,但检索数据并在登录用户视图中显示数据时遇到问题。我已经看了一些例子,但我肯定遗漏了一些东西,因为我可以输出一些数据,但不能输出我特别想要的字段。(电话号码和驾驶执照号码)

这是我的密码

Index.cshtml

 User Data: 



  @{

       System.Security.Claims.ClaimsPrincipal claimsPrincipal = Context.User 
     as System.Security.Claims.ClaimsPrincipal;
       System.Security.Claims.ClaimsIdentity id = claimsPrincipal.Identity 
       as System.Security.Claims.ClaimsIdentity;
       foreach (var claim in id.Claims)
       {
           <p>Claim: @claim.ToString()</p>
           <p>Claim More: @claim.p</p>
       }
}
用户数据:
@{
System.Security.Claims.ClaimsPrincipal ClaimsPrincipal=Context.User
如System.Security.Claims.ClaimsPrincipal;
System.Security.Claims.ClaimsIdentity id=claimsPrincipal.Identity
as系统、安全、索赔、索赔实体;
foreach(id.Claims中的var索赔)
{
索赔:@Claim.ToString()

索赔更多:@Claim.p

} }
家庭控制器

 [Authorize]
    public ActionResult Index()
    {

        var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationUser.MyDbContext()));

        // Get the current logged in User and look up the user in ASP.NET Identity
        var currentUser = manager.FindById(User.Identity.GetUserId());

        // Recover the profile information about the logged in user
        ViewBag.DriverLicense= currentUser.DrivingLicense;
        ViewBag.PhoneNumbers= currentUser.PhoneNumbers;

        return View();


    }
[授权]
公共行动结果索引()
{
var manager=newusermanager(newuserstore(newapplicationuser.MyDbContext());
//获取当前登录用户并在ASP.NET标识中查找该用户
var currentUser=manager.FindById(User.Identity.GetUserId());
//恢复有关已登录用户的配置文件信息
ViewBag.DriverLicense=currentUser.DrivingLicense;
ViewBag.phoneNumber=currentUser.phoneNumber;
返回视图();
}
ApplicationUser.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace Vidly2.Models
{
    public class ApplicationUser : IdentityUser
    {
        [Required]
        [StringLength(255)]
        public string DrivingLicense { get; set; }

        [Required]

        public int PhoneNumbers { get; set; }

        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }

        public class MyDbContext : IdentityDbContext<ApplicationUser>
        {
            public MyDbContext()
                : base("DefaultConnection")
            {
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.Linq;
使用System.Security.Claims;
使用System.Threading.Tasks;
使用System.Web;
使用Microsoft.AspNet.Identity;
使用Microsoft.AspNet.Identity.EntityFramework;
名称空间Vidly2.Models
{
公共类应用程序用户:IdentityUser
{
[必需]
[StringLength(255)]
公共字符串驱动许可证{get;set;}
[必需]
公共int电话号码{get;set;}
公共异步任务GenerateUserIdentityAsync(用户管理器)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
返回用户身份;
}
公共类MyDbContext:IdentityDbContext
{
公共MyDbContext()
:base(“默认连接”)
{
}
}
}
}

如果您需要任何附加信息,请告诉我您在哪个实体类上存储了附加信息?我想我提供了所有相关的控制器/类。你什么意思?你看到这个了吗?这是有用的。我让它工作了。感谢可能的副本