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