我已经阅读了几篇不同的文章,但我认为它们不适用于我的场景。
我正在尝试更新附加到用户的个人资料;但是,它不会让我通过 ModelState.IsValid 部分,因为我不包含密码字段。
我想更新一些字段,但不是密码字段。那么,如何从 RegisterModel 中省略这些?
这是我的代码:
'
' POST: /Account/EditRegistry
<HttpPost()> _
Public Function EditRegistry(registerModel As RegisterModel) As ActionResult
If ModelState.IsValid Then
' get membership from user name
Dim user = Membership.GetUser(registerModel.UserName)
' get user profile
Dim db0 = New UserProfileDbContext
Dim profile = db0.UserProfiles.Where(Function(p) p.UserId = user.ProviderUserKey).Single()
' TODO: update profile
profile.IsCompanyOwner = registerModel.IsCompanyOwner
profile.IsBlogOwner = registerModel.IsBlogOwner
profile.CompanyId = registerModel.Company
profile.BlogId = registerModel.Blog
db0.Entry(profile).State = EntityState.Modified
db0.SaveChanges()
' get model changes to membership object
' update membership object from model
End If
' If we got this far, something failed, redisplay form
Return View(registerModel)
End Function
编辑:
主意!我必须为此创建一个新模型吗?