title: mvc3 login form wrong username and password message
body: <pre><code>[HttpPost]
          public ActionResult Login(LoginModel model)
          {
              if (ModelState.IsValid)
              {
                  Authenticate(model.Username, model.Password);
                  return RedirectToAction("Index");
              }
              else
              {
                  return View(model);
              }
          }
  
          private void Authenticate(string userName, string password)
          {
              const string commaSeperatedRoles = "Administrator,Editor";
  
              if (userName == "xx" &amp;&amp; password == "xxx")
              {
                  FormsAuthenticationUtil.RedirectFromLoginPage(userName, commaSeperatedRoles, false);
              }
          }
  </code></pre>
  
  <p>and LoginModel</p>
  
  <pre><code>public class LoginModel
      {
          [Required(ErrorMessage="*")]
          [StringLength(10)]
          public string Username { get; set; }
  
          [Required(ErrorMessage = "*")]
          [StringLength(10)]
          public string Password { get; set; }
      }
  </code></pre>
  
  <p>and view</p>
  
  <pre><code>@using (Html.BeginForm())
  {
      &lt;table width="100%"&gt;
      &lt;tr&gt;
          &lt;td&gt;Username:&lt;/td&gt;
          &lt;td&gt;
              @Html.TextBoxFor(m =&gt; m.Username, new { @style = "width: 140px;" })
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Passwd:&lt;/td&gt;
          &lt;td&gt;
              @Html.PasswordFor(m =&gt; m.Password, new { @style = "width: 140px;" })
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;div class="napaka"&gt;Wrong username and password&lt;/div&gt;
      &lt;br /&gt;
      &lt;input type="submit" class="button" value="Login" /&gt;
  }
  </code></pre>
  
  <p>but now i always get this message of wrong login "Wrong username and password". How can i write this message only when username and password are wrong? I am using mvc3 in C#. Can i somehow send bool variable to view or what is the sbet way?</p>