Question

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..
Was it helpful?

Solution 2

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()

OTHER TIPS

I think you might be looking for

@Html.ValidationSummary()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top