【发布时间】:2014-01-23 16:50:24
【问题描述】:
您好,我正在使用 MVC 4 Asp.Net C# 开发一个 Web 应用程序。我有一个在页面顶部显示所有错误的设计。但是当使用数据注释时,我无法在表单之外显示验证摘要。任何人都可以提前帮助我解决这个问题。 以下是我的塞纳里奥
我的表单是这样的
@model ChrisFinnerty.Models.LocalPasswordModel
@{
ViewBag.Title = "Change Password";
}
@using (Html.BeginForm("ChangePassword", "Account", FormMethod.Post, new {@id = "FormChangePassword", @role = "form", @class = "form-horizontal well"}))
{
@Html.ValidationSummary()
<h2>Change Password</h2>
@Html.AntiForgeryToken()
@Html.PasswordFor(m => m.OldPassword, new {@class = "form-control"})
@Html.PasswordFor(m => m.NewPassword, new {@class = "form-control"})
@Html.PasswordFor(m => m.ConfirmPassword, new {@class = "form-control"})
<button type="submit" class="btn btn-default">Change Password</button>
<button type="button" class="btn btn-default" onclick="window.history.go(-1) ">Cancel</button>
}
但我想在通知 div 中的表单之外显示验证摘要
@model ChrisFinnerty.Models.LocalPasswordModel
@{
ViewBag.Title = "Change Password";
}
@Html.ValidationSummary() //*****Just want to add it here its not working****
@using (Html.BeginForm("ChangePassword", "Account", FormMethod.Post, new {@id = "FormChangePassword", @role = "form", @class = "form-horizontal well"}))
{
<h2>Change Password</h2>
@Html.AntiForgeryToken()
@Html.PasswordFor(m => m.OldPassword, new {@class = "form-control"})
@Html.PasswordFor(m => m.NewPassword, new {@class = "form-control"})
@Html.PasswordFor(m => m.ConfirmPassword, new {@class = "form-control"})
<button type="submit" class="btn btn-default">Change Password</button>
<button type="button" class="btn btn-default" onclick="window.history.go(-1) ">Cancel</button>
}
【问题讨论】:
-
只需将 div 移到表单中,您的问题就解决了……不知道有什么区别。
-
你也可以用CSS来实现这个东西。
-
表单位于页面底部,通知 div 位于页面顶部。它的设计限制我不能将通知 div 添加到表单中它会扰乱页面的布局:'(
-
DataAnnotations 会将错误消息绑定到那些特定的输入元素(因此它将与输入元素本身一起显示)。如果您只想显示错误列表,请尝试使用弹出错误消息jquery4u.com/plugins/10-jquery-alert-windows-prompts 您可以使用这些中的一些内容
-
亲爱的我只想在表单外显示@Html.validationssummary()
标签: c# asp.net-mvc asp.net-mvc-4