title: Displaying Invalid user name or password using MVC Validation
body: <p>I am using MVC validation to check if use name and password exit in database or not. <code>ModelState.IsValid</code> is true always even when I did not find any matching user.</p>
  
  <pre><code>if (objModel != null)
  {
      if (ModelState.IsValid &amp;&amp; Membership.ValidateUser(objUsersModel.UserName, objUsersModel.Password))
      {
          Profile.Initialize(objUsersModel.UserName.Trim(), true);
          FormsAuthentication.SetAuthCookie(objUsersModel.UserName, false);
          return RedirectToAction("Index", "Home");
      }
  }
  </code></pre>
  
  <p>How can I set this to false and set the values for error message in mvc view. Here is my MVC view .</p>
  
  <pre><code>&lt;form role="form"&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="exampleInputEmail1"&gt;User Name &lt;/label&gt;
          &lt;i class="fa fa-user"&gt;&lt;/i&gt;
          @Html.TextBoxFor(m =&gt; m.UserName, new { maxlength = 50, @class = "form-control" })
          @Html.ValidationMessageFor(u =&gt; u.UserName)
      &lt;/div&gt;
      &lt;div class="form-group"&gt; 
          &lt;label for="exampleInputPassword1"&gt;Password&lt;/label&gt;
          &lt;i class="fa fa-lock"&gt;&lt;/i&gt;
          @Html.PasswordFor(m =&gt; m.Password, new { maxlength = 50, @class = "form-control" })
          @Html.ValidationMessageFor(u =&gt; u.Password)
      &lt;/div&gt;
      &lt;div class="form-actions"&gt;
          &lt;label class="checkbox"&gt; &lt;input type="checkbox" class="uniform" value=""&gt; Remember me&lt;/label&gt;
          &lt;button type="submit" class="btn btn-danger"&gt;Submit&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>