0

I want to group my ValidationMessageFor at the top of the page instead of after each edit/textbox.

Is it possible to do something like this or is there any other way to achieve my idea?

@Html.Partial("_PartialView", MyModel)

@model MyModel
@foreach (var item in Model)
{
    @Html.ValidationMessageFor(item)
}

Instead of doing this:

@Html.ValidationMessageFor(model => model.Foo)
@Html.ValidationMessageFor(model => model.Bar)
@Html.ValidationMessageFor(model => model.etc..
Rob
  • 186
  • 5
  • 18
  • check this out...http://stackoverflow.com/questions/21529880/validation-is-only-applied-to-the-first-item-of-an-array – foxtrotZulu Mar 28 '14 at 14:20

2 Answers2

2

I think you might be looking for

@Html.ValidationSummary()

Vasil Dininski
  • 2,368
  • 1
  • 19
  • 31
1

i think these two steps are enough

1. Remove the Html.ValidationMessageFor()
2. Add Html.ValidationSummary(false, "Your custom summary message") inside using(html.BeginForm()
Kamlesh Arya
  • 4,864
  • 3
  • 21
  • 28
  • Follow-up question: Is it possible to get those messages triggered by javascript? I found this one that worked on the Html.ValidationMessageFor() `$('input[data-val=true]').on('blur', function () { $(this).valid() ;});` (now it only makes the textboxes border red) – Rob Mar 28 '14 at 14:33
  • yup..you can try unobtrusive..http://stackoverflow.com/questions/8538082/asp-net-mvc-3-required-steps-for-unobtrusive-client-side-validation-of-dynamic – Kamlesh Arya Mar 28 '14 at 14:37