所有这些字段都在模型中被赋予了必需的属性。但如果留空并按下提交按钮,则不会显示验证消息。
@using (Html.BeginForm("Login", "Account", null, FormMethod.Post))
{
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.AntiForgeryToken()
<br />
<div class="container">
<div class="row">
<h2 style="text-align: center;">@ViewBag.Title</h2>
<div class="col-sm-6 col-md-4 col-md-offset-4">
<div class="account-wall">
<h3 style="text-align: center; color: #b3b3b3;">Login to your account</h3>
<div class="form-signin">
@*Email*@
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = @Html.DisplayNameFor(m => m.Email) })
@Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
@*Password*@
@Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = @Html.DisplayNameFor(m => m.Password) })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
@*Submit*@
<div class="centered">
<button type="button" class="btn btn-success " typeof="submit">
Login
</button>
</div>
<a href="@Url.Action("Register", "Account")"><span>Register</span></a>
</div>
</div>
</div>
</div>
</div>
}