在SQL Server中编辑UserInformation和SaveChanges吗?

问题描述 投票:0回答:1

我正在尝试使用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

sql-server asp.net-core asp.net-core-mvc asp.net-core-identity
1个回答
0
投票

您实际上从未在用户对象上设置IsActive。请注意,“ =”和“ ==”之间是有区别的。

尝试此代码:

 ApplicationUser active = await _application.Users.FindAsync(Model.Email);
 active.IsActive = Model.IsActive;
 _application.Update(active);
 await _application.SaveChangesAsync();
© www.soinside.com 2019 - 2024. All rights reserved.