public IActionResult DoLogIn(LogInViewModel logInViewModel) { // Get the Id of the User var userId = _userBusinessLogic.LogIn(logInViewModel.Name, logInViewModel.Pass); // Check if the login failed if (userId == null) { return(View("Index", new LogInViewModel() { ErrorMessage = "Incorrect username or password" })); } // Create new Session HttpContext.Session.SetInt32("UserId", (int)userId); // Pass the success-message through the TempData, because the model cannot be passed TempData["SuccessMessage"] = "Successfully logged in"; return(RedirectToAction("Index", "Home")); }