1
votes

I am trying to display a summary error message on a form as well as property level errors.

The property errors get rendered using html.validationmessagefor(model =>...) which works fine.

But when there is one or more validation errors, I want html.ValidationSummary(true) to display the message "Your form is missing some details - see below".

There also might be some server side validation which will occur post submit and will be added with ModelState.AddError.

How can I get a class level dataattribute (presumably using [AttributeUsage(AttributeTargets.Class)]) to display in the summary validation using unobtrusive validation?

1
Unless there is a better way to do this... - user1654348

1 Answers

0
votes

Is this what you are looking for:

@using (Html.BeginForm())
{
        @Html.ValidationSummary(true)
        @Html.ValidationSummary("Errors:")

        <div>
            @Html.EditorFor(model => model.PathToExcel)
            @Html.ValidationMessageFor(model => model.PathToExcel)
        </div>

            <div>
            <input type="submit" value="Load" />
        </div>
}

this uses 2 ValidationSummary's, one to fill the ValidationMessageFor-fields and one to use a Summary. Summary only works after Submitting.