I have method that add roles for user. It works fine when it it constants string. Now i want to give role name from input and here i have problem with passing text to actionlink. How to do that ? Here is the code that i have working with constants string:
View:
@model AdminMVC.Models.Admin.UserViewModel
<input class="form-control" type="text" name="role" placeholder="Role name">
@Html.ActionLink("Add role", "AddRoleToUser", new { id = Model.ApplicationUser.Id }, new { @class = "fas fa-user-edit" })
Controller:
public async Task<IActionResult> AddRoleToUser(string id, string role)
{
var user = await _userManager.FindByIdAsync(id);
if (await _roleManager.RoleExistsAsync("NewRole"))
{
await _userManager.AddToRoleAsync(user, "NewRole");
}
return RedirectToAction("Roles");
}