如何在SqlServer中编辑UserInformation和SaveChanges?

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

我正在尝试使用asp.net-core更改Sqlserver中的列(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
投票
尝试此代码:

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.