I want to update User Roles by using a select and post it to db. The select is working fine for RoleName but when I change or add a role, the RoleId has to be updated too. How do I do that in Razor pages?
With the below code only the RoleName is updated, for RoleId I get error because its valuue is null
- UserRoleClassName = await _context.Roles.Select(a => new SelectListItem
- {
- Value = a.Id.ToString(),
- Text = a.Name
- }).ToListAsync();
- <div class="col-3">
- <label for="RoleName">Role Name</label>
- <select name="Role" class="form-control" asp-for="AppIdentityRole.Role" asp-items="Model.UserRoleClassName"></select>
- </div>
- <input hidden name="RoleId" asp-for="AppIdentityRole.RoleId" class="form-control" value="@Model.UserRoleClassName" />