Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将ApplicationUser属性添加到模型时,Create ActionResult不起作用_C#_Asp.net Mvc_Asp.net Identity - Fatal编程技术网

C# 将ApplicationUser属性添加到模型时,Create ActionResult不起作用

C# 将ApplicationUser属性添加到模型时,Create ActionResult不起作用,c#,asp.net-mvc,asp.net-identity,C#,Asp.net Mvc,Asp.net Identity,我有问题已经20天了。在我的模型“Colocataires”中,有一个属性类型为ApplicationUser“Publisher”。这意味着一个托管的发布者就是他自己的用户。所以问题是ModelState始终为false,所以创建从未完成。 型号: 身份模型: public class ApplicationUser : IdentityUser { [DisplayName("Nom"),Required] public string LastName { get;

我有问题已经20天了。在我的模型“Colocataires”中,有一个属性类型为ApplicationUser“Publisher”。这意味着一个托管的发布者就是他自己的用户。所以问题是ModelState始终为false,所以创建从未完成。 型号:

身份模型:

    public class ApplicationUser : IdentityUser
{
    [DisplayName("Nom"),Required]
    public string LastName { get; set; }

    [DisplayName("Prenom"), Required]
    public string FirstName { get; set; }

    [DisplayName("Sexe"), Required]
    public string Gender { get; set; }

    [DisplayName("Age"), Required]
    public int Age { get; set; }

    [DisplayName("Telephone"), Required]
    public string Tel { get; set; }


    public ICollection<OffreDeLocation> OffresLocation { get; set; }

    public ICollection<Colocataire> Colocatires { 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;
    }
}

当我删除ApplicationUser属性时,它工作正常,因此我不知道我缺少了什么,请帮助

缺少一个必填字段。在“ModelState.IsValid”上放置一个断点,然后深入研究its键。其中一个选项具有键和值。该值将告诉您错误是什么。请参见:
    public class ApplicationUser : IdentityUser
{
    [DisplayName("Nom"),Required]
    public string LastName { get; set; }

    [DisplayName("Prenom"), Required]
    public string FirstName { get; set; }

    [DisplayName("Sexe"), Required]
    public string Gender { get; set; }

    [DisplayName("Age"), Required]
    public int Age { get; set; }

    [DisplayName("Telephone"), Required]
    public string Tel { get; set; }


    public ICollection<OffreDeLocation> OffresLocation { get; set; }

    public ICollection<Colocataire> Colocatires { 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;
    }
}
        [HttpPost]
    [ValidateAntiForgeryToken]
    [Route("Create")]
    public ActionResult Create(Colocataire colocataire, HttpPostedFileBase upload)
    {
        ViewBag.currentUser = User.Identity.GetUserName();
        if (ModelState.IsValid)
        {
            string path = Path.Combine(Server.MapPath("~/Uploads/Colocataires"), upload.FileName);
            upload.SaveAs(path);
            colocataire.PhotoColoc = upload.FileName;
            colocataire.DateDajout = DateTime.UtcNow;
            db.Colocataires.Add(colocataire);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(colocataire);
    }