1

I'm using asp.net core and I get list of roles (Identity roles) like:

   [HttpGet]   
   public async Task<IActionResult> GetAvailableUserRoles()
        {
            var roles =  _roleManager.Roles.ToList();
            return Ok(roles);
        }

So I want to display this list on view

I have an idea that first approach is to call controller like:

<form asp-controller="security" asp-action="GetAvailableUserRoles" method="get">

</form>

Now, how can I do a dropdown with RoleId and Name?

ekad
  • 14,436
  • 26
  • 44
  • 46
Jonathan
  • 601
  • 9
  • 26
  • Refer this [Select Tag Helper in ASP.NET Core MVC](https://stackoverflow.com/questions/34624034/select-tag-helper-in-asp-net-core-mvc) – Shyju Nov 12 '18 at 23:49
  • What is the point of setting `asp-action` to `GetAvailableUserRoles` ? asp-action value should be the action method which handles your form submit. Refer the above post and pass the items needed to build the SELECT element from your GET action method of the view. – Shyju Nov 12 '18 at 23:50
  • I feel like this Q&A is also a good fit for this.. https://stackoverflow.com/questions/27090227/trying-to-get-all-roles-in-identity – Joseph Poirier Apr 08 '19 at 00:35

0 Answers0