Hi,
I had exactly the same issue after upgrading one of the sites from Epi 7 to 7.5.
I have used in view
@Html.ValidationSummary()
and after upgrade errors were there multiplied by 3 e.g. when there were 5 errors on one form validation summary showed there 15 errors (each of errors repeated 3 times)
As a solution I have created own extension method which filters the error messages:
public static MvcHtmlString FilteredValidationSummary(this HtmlHelper html, ModelStateDictionary modelState)
{
List errors = new List();
StringBuilder builder = new StringBuilder();
builder.AppendLine(@"");
builder.AppendLine("");
foreach (var state in modelState.Values)
{
foreach (var error in state.Errors)
{
if (!errors.Contains(error.ErrorMessage))
{
errors.Add(error.ErrorMessage);
builder.AppendFormat(@"- {0}
", error.ErrorMessage);
}
}
}
builder.AppendLine("
");
builder.AppendLine("");
if (errors.Count > 0)
return new MvcHtmlString(builder.ToString());
else
return null;
}
and just callled that from the view:
@Html.FilteredValidationSummary(ViewContext.ViewData.ModelState)
I've just run into the same issue and was about to do much the same as yourself Grzegorz, so thanks for saving me some legwork.
Just a small update on code snippet :)
public static MvcHtmlString FilteredValidationSummary(this HtmlHelper html, ModelStateDictionary modelState) { var errors = new List<string>(); var builder = new StringBuilder(); builder.AppendLine(@"<div class=""validation-summary-errors"">"); builder.AppendLine("<ul>"); foreach (var error in modelState.Values.SelectMany(state => state.Errors.Where(error => !errors.Contains(error.ErrorMessage)))) { errors.Add(error.ErrorMessage); builder.AppendFormat(@"<li>{0}</li>", error.ErrorMessage); } builder.AppendLine("</ul>"); builder.AppendLine("</div>"); return errors.Count > 0 ? new MvcHtmlString(builder.ToString()) : null; }
This workaround works fine only if you distinguish the particular input fields by ToolTip in the xform definition. If you leave the ToolTip empty then all error messages will be the same, e.g. for required fileds the message is "Vaadittua kenttää ei ole määritetty". So if you have 2 mandatory inputs then the workaround solution above will display only one error message in the validation summary, which is wrong :( So definitely this whole issue should be reported as bug to EPiServer.
Hello.
In my xform, we have a field where the user writes his/her email address. We've set this to validate as an email address. The validation works, but when it prints out the "email address didn't pass validation" error message in the validation summary at the top, it prints out the same message 3 times, even though it is just 1 field that hasn't passed validation.
Does anyone know what this is?