public ActionResult Login(AccessModel model) { if (!ModelState.IsValid) { string sError = ""; foreach (var item in ModelState) { if (sError.Length > 0) { sError += ", "; } if (item.Value.Errors.Count > 0 && !item.Value.Errors[0].ErrorMessage.Contains("mail")) { sError += item.Value; } } if (sError.Length > 0) { model.ErrorMessage = sError; return(View(model)); } } bool bRet = model.LogIn(); if (bRet) { UserCache.RemoveFromCache(0, model.User.IPAddress); UserCache.AddToCache(model.User); model.GoHome = true; } //if you made it this far, the login didn't work return(View(model)); }