[英]The error message does not go away when I try again to insert username password
我添加了檢查和驗證,如果用戶添加了無效的用戶名和密碼,系統會提示消息。
但我想要的是,如果用戶再次嘗試插入用戶名和密碼,我想刪除該消息。 目前,該消息並未消失。
碼:
[HttpPost]
[ValidateInput(false)]
public ActionResult ValidateUser() {
string strUsername = Sanitizer.GetSafeHtmlFragment(Convert.ToString(Request.Form["txtUsername"]));
string strPassword = Sanitizer.GetSafeHtmlFragment(Convert.ToString(Request.Form["txtPassword"]));
string strDbError = string.Empty;
strUsername = strUsername.Trim();
strPassword = strPassword.Trim();
string strUserName = "";
string strCurrentGroupName = "";
int intCurrentGroupID = 0;
string controller = "";
string action = "";
UserProviderClient ObjUMS = new UserProviderClient();
bool result = false;
if (strUsername != "" || strPassword != "") {
result = ObjUMS.AuthenticateUser(strUsername, strPassword, out strDbError);
try {
if (result == true) {
UMS ObjUMSDATA = new UMS();
//strUserName = System.Web.HttpContext.Current.User.Identity.Name.Split('\\')[1];
strUserName = strUsername;
_UMSUserName = strUserName;
if (!string.IsNullOrEmpty(strUserName)) {
List < UMSGroupDetails > lstUMSGroupDetails = null;
List < UMSLocationDetails > lstUMSLocationDetails = null;
ObjUMSDATA.GetUMSGroups(strUserName, out strCurrentGroupName, out intCurrentGroupID, out lstUMSLocationDetails, out lstUMSGroupDetails);
if (strCurrentGroupName != "" && intCurrentGroupID != 0) {
ViewBag.LoginUserName = strUserName.ToUpper();
ViewBag.CurrentGroupName = strCurrentGroupName;
ViewBag.CurrentGroupID = intCurrentGroupID;
ViewBag.GroupDetails = lstUMSGroupDetails;
ViewBag.LocationDetails = lstUMSLocationDetails;
TempData["LoginUserName"] = strUsername.ToUpper();
TempData["Location"] = lstUMSLocationDetails;
TempData["strCurrentGroupName"] = strCurrentGroupName;
TempData.Keep();
} else {
ModelState.AddModelError(string.Empty, "You are not registered. Please register first.");
return View("Login");
}
}
}
if (strCurrentGroupName == "SAP Executive") {
action = "Assign";
controller = "App";
} else if (strCurrentGroupName == "Maintenance Lead") {
//return RedirectToAction("App", "Certify");
action = "Certify";
controller = "App";
} else if (strCurrentGroupName == "NEIQC CMM") {
//return RedirectToAction("App", "Approver");
action = "Approver";
controller = "App";
} else {
ModelState.AddModelError(string.Empty, "Invalid Username and password");
return View("Login");
}
} catch (Exception ex) {
ApplicationLog.Error("Error", "ValidateUser", ex.Message);
}
} else {
ModelState.AddModelError(string.Empty, "Invalid Username and password");
return View("Login");
}
//Session["isUserAuthenticated"] = result;
return RedirectToActionPermanent(action, controller);
}
HTML:
<div class="loginForm" id="loginForm" ng-controller="UserSelection">
@using (Html.BeginForm("ValidateUser", "Home", FormMethod.Post)) {
<div class="formGroup hide1">
<input type="text" id="txtUsername" class="formInput" name="txtUsername" ng-model="LoginUserName" />
<span class="focusInput" data-placeholder="Username"></span>
</div>
<div class="password formGroup hide1">
<input type="password" id="txtPassword" class="formInput" name="txtPassword" ng-model="LoginPassword" />
<span class="focusInput" data-placeholder="Password"></span>
</div>
<div class="submit formGroup hide1">
@*<button type="button" id="submit" onclick="return validateUser();">Submit</button>*@
<button type="submit" id="submit" ng-disabled="(!LoginUserName||!LoginPassword)" onclick="return submitLogin();" class="loginUser"><i class="fa fa-refresh fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> Submit</button>
</div>
<div class="error">
@Html.ValidationSummary(false, "", new { @class = "text-danger " })
</div>
<div class="ums">
<a href="#" target="_blank" title="Contact Jio.GISOperations@ril.com for registration and support.">Register</a>
</div>
@*
<div class="ums"><a href="#" target="_blank">Register</a></div>*@ }
</div>
以上是我的代碼,請說明我的錯誤。
請嘗試以下代碼。
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(function () {
$('#txtUserName').blur(
function () {
$('.validation-summary-errors').remove();
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.