简体   繁体   中英

MVC 4 Show validation Summary outside the Form?

Hi I am developing a web application in MVC 4 Asp.Net C#. I have a design which showing all the error at top of the page. But when using Data Annotations I am unable to show validation summary outside the form. Can any one please help me out to overcome this issue thans in advance. Following is my Senario

My forms look like this

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

But I want like that show validation summary outside the form in notification 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>
         }

Just add @Html.ValidationSummary() out side the form. I had same problem see this. MVC3 ValidationSummary Control

See this example http://mahaafifi.blogspot.in/2011/12/multiple-validation-summary-at-single.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM