Вопрос

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..
Это было полезно?

Решение 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()

Другие советы

I think you might be looking for

@Html.ValidationSummary()

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top