[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> EditUser(EditUserViewModel viewModel)
{
if (!ModelState.IsValid) return View();
var user = await _userManager.FindByIdAsync(viewModel.Id);
if (user == null) return RedirectToAction("Index", "Admin");
var userClaims = await _userManager.GetClaimsAsync(user);
if (viewModel.Admin)
{
if (!userClaims.Select(c => c.Value == "Admin").Any())
await _userManager.AddClaimAsync(user, new Claim("Admin", "Admin"));
}
else
{
if (userClaims.Select(c => c.Value == "Admin").Any())
await _userManager.RemoveClaimAsync(user, new Claim("Admin", "Admin"));
}
user.FirstName = viewModel.FirstName;
user.LastName = viewModel.LastName;
var result = await _userManager.UpdateAsync(user);
if (result.Succeeded) return RedirectToAction("Index", "Admin");
ModelState.AddModelError("", "Something went wrong");
return View();
}
检查管理员声明存在时给出错误:
c.值=错误 CS0103:名称"c"在当前上下文中不存在
线程0x990已退出,代码为 0 (0x0(。
错误 错误图像
正如评论中所讨论的,没有任何问题。Visual Studio只是向您展示了c
的潜在价值,但它尚未在范围内。
正如您现在所看到的,只要您在 LinqSelect
中输入断点,c
确实有一个值。
最后,线程消息是一条常规消息,指示某个线程已完成其工作。