首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >EntityType'MyProfile'没有定义键。如何定义EntityType?

EntityType'MyProfile'没有定义键。如何定义EntityType?

提问于 2018-01-31 23:46:20
回答 2关注 0查看 224

这是我的代码:

代码语言:txt
复制
[HttpPost]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

            if (createStatus == MembershipCreateStatus.Success)
            {

                FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                MembershipUser myObject = Membership.GetUser();
                Guid UserID = (Guid)myObject.ProviderUserKey;
                MyProfile profile = new MyProfile();
                profile.Address = model.Address;
                profile.City = model.City;
                profile.Zip = model.Zip;
                profile.State = model.State;
                profile.UserId = UserID;
                db.Profiles.Add(profile);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
            }
        }

        // If we got this far, something failed, redisplay form
        ViewBag.PasswordLength = MembershipService.MinPasswordLength;
        return View(model);
    }

这是我的MyProfile类:

代码语言:txt
复制
   namespace MatchGaming.Models
{
    [Bind(Exclude = "ProfileId")]
    public class MyProfile
    {
        [ScaffoldColumn(false)]
        public int ProfileId { get; set; }

        public Guid UserId { get; set; }

        [DisplayName("Address")]
        public string Address { get; set; }

        [DisplayName("City")]
        public string City { get; set; }

        [DisplayName("Zip")]
        public string Zip { get; set; }

        [DisplayName("State")]
        public string State { get; set; }


    }
}

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档