我正在开发一个ASP.NET Core 2.0项目,我遇到了与此相匹配的问题:
<a asp-controller="User" asp-action="AddFriend" asp-route-id="@item.Id">Add
Friend</a>
到UserController中的方法:
[ValidateAntiForgeryToken]
public IActionResult AddFriend(string id)
{
if (id == null)
{
return NotFound();
}
User currentUser = _manager.GetUserAsync(HttpContext.User).GetAwaiter().GetResult();
User targetUser = _service.GetById(id);
_service.AddFriend(currentUser, targetUser);
return RedirectToAction(actionName: nameof(Index), controllerName: "Home");
}