I have a code like this:
public IActionResult Urgent(TodoTable t)
{
var Task = db.TodoTables.SingleOrDefault(i => i.Id == t.Id);
Task!.Urgent = t.Urgent; // If the value is True it will change to False and if False it will change to True.
db.SaveChanges();
return RedirectToAction("Index");
}
And Index.cshtml:
<a class="dropdown-item" href="/TodoTables/Urgent/@item.Id">@(item.Urgent ? "Unurgent" : "Urgent")</a>
If the Urgent value in the database is True, it will be False, and if False, it will be True. But I could not do this on the Controller side. Only True becomes False, then does not become True again.
How can I do that? Thanks for the help.
>Solution :
Can you try replacing your code like this?
Task.Urgent = !Task.Urgent;