简体   繁体   English

当我再次尝试插入用户名密码时,错误消息不会消失

[英]The error message does not go away when I try again to insert username password

I have added a check and validation where if a user adds an invalid username and password, then the system prompts message. 我添加了检查和验证,如果用户添加了无效的用户名和密码,系统会提示消息。

But what I want is, I want to remove that message if user again goes and try to insert the username and password. 但我想要的是,如果用户再次尝试插入用户名和密码,我想删除该消息。 Currently, the message doesn't go away. 目前,该消息并未消失。

Code: 码:

[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: 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>

Above is my code, please suggest where I am wrong. 以上是我的代码,请说明我的错误。

Please try the below code. 请尝试以下代码。

   <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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM