Skip to content

ModelStateWrapper

Implements IMessageContainer over ModelStateDictionary, giving domain/service code a validation-agnostic way to report errors, warnings, and informational messages while de-duplicating repeated text so users do not see the same message multiple times.

Purpose

  • Implements IMessageContainer over ModelStateDictionary, giving domain/service code a validation-agnostic way to report errors, warnings, and informational messages while de-duplicating repeated text so users do not see the same message multiple times.

Context

  • Namespace: SAIF.Web.Mvc
  • Assembly/package: SAIF.Framework.Web.Mvc (source-shipping NuGet package)
  • Kind: class (service)

Public members

Member Signature Purpose
Warnings public IList<string> Warnings { get; } Accumulated warning messages, each appended at most once regardless of how many callers report the same text.
Informationals public IList<string> Informationals { get; } Accumulated informational messages, de-duplicated the same way as Warnings.
AddError(string propertyName, string message) public void AddError(string propertyName, string message) Adds a model-state error for the property, blanking the message text on repeat occurrences so it displays only once; see the "Collect user messages through ModelStateWrapper" operation.
AddWarning(string message) public void AddWarning(string message) Appends a warning only if no case-insensitive duplicate already exists.
AddInformation(string message) public void AddInformation(string message) Appends an informational message only if no case-insensitive duplicate already exists.

Behavioral notes

  • AddError still creates a model-state entry for the property even when the message text is blanked out, so field-level error highlighting is preserved (see BR-37).

Sources

  • src/Web.Mvc/Classes/ModelStateWrapper.cs