MVC 4在表单外显示验证摘要?

时间:2014-01-23 04:52:35

标签: c# asp.net-mvc asp.net-mvc-4

您好我正在使用MVC 4 Asp.Net C#开发一个Web应用程序。我有一个设计,显示页面顶部的所有错误。但是在使用数据注释时,我无法在表单外显示验证摘要。任何人都可以帮我解决这个问题。 以下是我的Senario

我的表单看起来像这样

    @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>
         }

1 个答案:

答案 0 :(得分:-1)

只需在表单旁边添加@Html.ValidationSummary()即可。我有同样的问题看到这个。 MVC3 ValidationSummary Control

请参阅此示例http://mahaafifi.blogspot.in/2011/12/multiple-validation-summary-at-single.html