簡體   English   中英

值不能為空。 參數名稱:值

[英]Value cannot be null. Parameter name: value

我想在aspnet用戶表中添加新字段..我還在帳戶視圖模型中添加了用戶名屬性..

 public class ApplicationUser : IdentityUser<int, UserLogin, UserRole, UserClaim>
{
    public DateTime? ActiveUntil;

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
    {
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        return userIdentity;
    }
    public string  UserName { get; set; }

}

它給出了以下錯誤值不能為空。 參數名稱:值

      {
Line 53:             // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
Line 54:             var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
Line 55:             // Add custom user claims here

我通過在 SecurityStamp 字段中放置一個隨機字符串解決了這個問題。 要生成此字符串,只需使用 Guid.NewGuid ()

因此,您可以將代碼更改為如下所示: enter code here

public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
{
    if (string.IsNullOrEmpty(this.SecurityStamp))
    {
        this.SecurityStamp = Guid.NewGuid().ToString().Replace("-", "");
    }

    var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
    return userIdentity;
}

我也面臨同樣的錯誤。 當我將[Display]更改為這個時,我發現在Model

[Display(Name = "")]
public string Budget { get; set; }

取而代之的是:

[Display(Name = "Budget")]
public string Budget { get; set; }

名稱的value未定義...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM