Search code examples
asp.net-mvcasp.net-coreasp.net-identity

Getting error whenever i try to assign role to user in Identity Framework


here I am again.. I am trying to assign roles to the users which are registerd but whenever i try to update user details like assigning role i am getting role list required error. I try to debug the code but i didn't work. Need help from seniors!

View side code: enter image description here

Controller side code: enter image description here

Application user class which is inherited from identity user: enter image description here

This is the output i getting: enter image description here


Solution

  • Your validation error message has already explained the problem. When you submit the form, you only fill in the three fields of Name, Email and RoleId, but the Role and RoleList are not filled. Make these two fields nullable if you don't intend to populate them when the form is submitted:

    [NotMapped]
    public string? Role { get; set; }
    [NotMapped]
    public IEnumerable<SelectListItem>? RoleList { get; set; }