我正在尝试使用ASP.NET Core更改SQL Server中的列(IsActive)
AdminController:
public AdminController (ApplicationDbContext application)
{
_application = application;`}
[HttpGet]
public IActionResult ActiveUser() { return View();}
[HttpPost]
public async Task<ActionResult> ActiveUser(ApplicationUser Model)
{
ApplicationUser active = await _application.Users.FindAsync(Model.Email);
var a = active.IsActive == true;
if(active.IsActive == false) { a = Model.IsActive; }
_application.Update(active);
await _application.SaveChangesAsync();
return View();
此代码运行无任何错误,但实际上(IsActive)在我的数据库中没有更改。如何设置IsActive==true
?
您实际上从未在用户对象上设置IsActive。请注意,“ =”和“ ==”之间是有区别的。
尝试此代码:
ApplicationUser active = await _application.Users.FindAsync(Model.Email);
active.IsActive = Model.IsActive;
_application.Update(active);
await _application.SaveChangesAsync();