I have below form written in mvc3 razor. I want to display a message when user has entered incorrect password. I have placed a label to display message but dont know how to accomplish show/hide in mvc. Please help.
@using (Html.BeginForm("Authenticate", "Authorization", FormMethod.Post, new { autocomplete = "off" }))
{
    < div>
    < fieldset>
        <legend > User Information </legend>
        <div class="editor-label">
            @Html.Label("Password")
            @Html.TextBox("password")
            @Html.ValidationMessageFor(m => m.password)
            @Html.Label("Incorrect Password")
        </div>
        <p>
            @Html.Hidden("tab", ViewData["tab"])
            <input type="submit" value="Submit" />
        </p>
    </fieldset>
</div>
}
                In the controller action that is supposed to validate the credentials you could add a modelstate error:
ModelState.AddModelError("password", "The username or password is incorrect");
Create a new ASP.NET MVC application using the built-in wizard in Visual Studio and navigate to ~/Controller/AccountController.cs. Then look at the LogOn POST action. It adds a general modelstate error when the credentials are invalid:
ModelState.AddModelError("", "The user name or password provided is incorrect.");
and this error is displayed using a ValidationSummary helper inside the view:
@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With