我有用mvc3剃刀写的下面的表格。当用户输入了错误的密码时,我想显示一条消息。我已经放置了一个标签来显示消息,但不知道如何在mvc中实现显示/隐藏。请帮帮忙。
@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>
}发布于 2012-06-12 01:17:59
在应该验证凭据的控制器操作中,您可以添加一个模型状态错误:
ModelState.AddModelError("password", "The username or password is incorrect");使用Visual Studio中的内置向导创建一个新的ASP.NET MVC应用程序,并导航到~/Controller/AccountController.cs。然后看看LogOn POST操作。当凭证无效时,它会添加一个一般的模型状态错误:
ModelState.AddModelError("", "The user name or password provided is incorrect.");在视图中使用ValidationSummary帮助器显示此错误:
@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")https://stackoverflow.com/questions/10984618
复制相似问题