title: Error message doesn't show on wrong credentials login using ASP.NET
body: <p>My error message does not appear on failed login using ASP.NET MVC. When I try to login using a user account that does not exist, or with a wrong credentials,  the error message does not appear. I want to show message in alert popup or in a message if  username and password will be wrong.</p>
  <p>Here is code for the login:</p>
  <p><strong>LoginController.cs</strong></p>
  <pre><code>[HttpGet]
  public ActionResult StaffLogin()
  {
      return View();
  }
  
  [HttpPost]
  public ActionResult StaffLogin(Patron p)
  {
      var credentials = c.Staffs.FirstOrDefault(x =&gt; x.Username == p.Username &amp;&amp; x.Password == p.Password);
  
      if (credentials != null)
      {
          ViewBag.Message = &quot;UserName and password is correct! Welcome!&quot;;
          FormsAuthentication.SetAuthCookie(credentials.Username, false);
          Session[&quot;user&quot;] = credentials.user.ToString();
          // return RedirectToAction(&quot;Index&quot;, &quot;Patron&quot;);
      }
      else
      {
          ViewBag.Message = &quot;You have entered wrong credentials. Please Try Again!&quot;;
          ViewBag.Message = &quot;This is second message. UserName or password is wrong&quot;;
          return View();
      }
  }
  </code></pre>
  <p><strong>LoginIndex.cshtml</strong></p>
  <pre><code>&lt;div class=&quot;register-in&quot;&gt;
      &lt;a class=&quot;book popup-with-zoom-anim button-isi zoomIn animated&quot; data-wow-delay=&quot;.5s&quot; href=&quot;#small-dialog&quot;&gt; 1. Staff Login Popup Window&lt;/a&gt;
      &lt;br&gt;
  &lt;/div&gt;
  
  &lt;div class=&quot;pop-up&quot;&gt;
      &lt;div id=&quot;small-dialog&quot; class=&quot;mfp-hide book-form&quot;&gt;
          &lt;div class=&quot;login-form login-form-left&quot;&gt;
              &lt;div class=&quot;agile-row&quot;&gt;
                  &lt;h3&gt; 1. Staff Login Window &lt;/h3&gt;
                  &lt;span class=&quot;fa fa-lock&quot;&gt;&lt;/span&gt;
                  &lt;div class=&quot;clear&quot;&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;login-agileits-top&quot;&gt;
                      @using (Html.BeginForm(&quot;StaffLogin&quot;, &quot;Login&quot;, FormMethod.Post))
                      {
                          &lt;input type=&quot;text&quot; class=&quot;name&quot; name=&quot;Username&quot; Placeholder=&quot;Your Mail&quot; required=&quot;&quot; /&gt;
                          &lt;input type=&quot;password&quot; class=&quot;password&quot; name=&quot;Password&quot; Placeholder=&quot;Password&quot; required=&quot;&quot; /&gt;
                          @Html.ValidationMessage(&quot;LogOnError&quot;)
  
                          &lt;input type=&quot;submit&quot; value=&quot;Click to Login&quot;&gt;}
                      &lt;/div&gt;
  
                      &lt;div class=&quot;login-agileits-bottom&quot;&gt;
                      &lt;/div&gt;
  </code></pre>
  <p>Sir/Ma'am your answers would be of great help. Thank you++</p>