I have asp-route-id working in one instance:
It works from an anchor tag like this:
<a id="editModal" data-toggle="modal" data-target="#modal_box"
class="btn btn-sm btn-primary"
asp-action="Edit" asp-route-id="@user.Id">Edit</a>
and is received like this:
public async Task<PartialViewResult> DeleteConfirm(string Id) =>
PartialView("_DeleteConfirm", await _userManager.FindByIdAsync(Id));
This method receives the correct id.
The next example has the route id in the form tag like this:
<div class="modal-footer">
<form asp-controller="Account" asp-action="Delete" asp-route-id="@Model.Id" method="post">
<button type="submit" class="btn btn-primary"
asp-action="Delete">Yes - Delete this User</button>
<a asp-action="Index" class="btn btn-default">Cancel</a>
</form>
</div>
and I am trying to receive the Id here:
[HttpPost]
public async Task<IActionResult> Delete(string Id)
{
AppUser user = await _userManager.FindByIdAsync(Id);
if (user != null)
{
IdentityResult result = await _userManager.DeleteAsync(user);
if (result.Succeeded)
{
return RedirectToAction("Index");
}
else
{
AddErrorsFromResult(result);
}
}
else
{
ModelState.AddModelError("", "User Not Found");
}
return View("Index", _userManager.Users);
}
But in this case the parameter is coming in null.
It should work from the from tag. I got this from the first Identity Chapter in Adam Freemans APress MVC Core book and it worked when I typed it in for that example.