Custom ValidationSummary template Asp.net MVC 3

前端 未结 7 2319
耶瑟儿~
耶瑟儿~ 2020-11-30 18:59

I am working on a project with Asp.Net MVC3

In a View I have @Html.ValidationSummary(true) and as usually it produces

7条回答
  •  孤独总比滥情好
    2020-11-30 19:48

    Building upon flos's answer, I made it compatible with Microsoft's jQuery Unobtrusive Validation and added Bootstrap's 3 panel styling. Here's the new code:

    @model ModelStateDictionary
    
    
    Please, correct the following errors:
      @foreach(var modelError in Model.SelectMany(keyValuePair => keyValuePair.Value.Errors)) {
    • @modelError.ErrorMessage
    • }

    You can read about it in full detail here:

    Creating a custom ASP.NET MVC @Html.ValidationSummary styled with Bootstrap 3 panel

    I also created a sample ASP.NET MVC project to show this custom ValidationSummary in action. Get it here:

    https://github.com/leniel/AspNetMvcCustomHtmlValidationSummary

提交回复
热议问题