找不到类型或命名空间名称“应用程序用户”

时间:2016-03-25 11:32:21

标签: c# asp.net asp.net-mvc

我是C#的新手,我正在创建一个ASP.NET MVC应用程序。我在尝试按照此处的说明操作时,目前收到上述错误:Extending ASP.NET Identity

我正在尝试让我的代码在用户登录后显示用户的名字而不是他们的电子邮件地址。

这是我的_LoginPartial.cshtml

的代码
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
    @Html.AntiForgeryToken()

    <ul class="nav navbar-nav navbar-right">
        <li>
            @{
                var manager = new UserManager<ApplicationUser>(new Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>(new ApplicationDbContext()));
                var currentUser = manager.FindById(User.Identity.GetUserId());
            }
            @Html.ActionLink("Hello " + currentUser.FName + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
        </li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
    </ul>
    }
}
else
{
    <ul class="nav navbar-nav navbar-right">
        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
    </ul>
}

这是我在IdentityModels.cs中找到的ApplicationUser类

public class ApplicationUser : IdentityUser
{
    public string FName { get; set; }
    public string LName { 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;
    }
}

非常感谢任何建议

2 个答案:

答案 0 :(得分:0)

在您的视图中添加@using ContactManager.Models.ApplicationUser

答案 1 :(得分:0)

我通过将以下内容放入_LoginPartial.cshtml:

来实现它
Table.FieldName in (@MultiValue)

另一个建议导致了不同的错误消息。 谢谢你的帮助!