---
title: Collect user messages through ModelStateWrapper
summary: Record error, warning, and informational messages while de-duplicating repeated text.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-09-17
library: SAIF.Framework.Web.Mvc
reference_type: package
operation_id: OP-17
trigger: Domain or service code writing messages through `IMessageContainer`
---

# Collect user messages through ModelStateWrapper

Record error, warning, and informational messages while de-duplicating repeated text. Trigger: Domain or service code writing messages through `IMessageContainer`.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-17 |
| **Trigger** | Domain or service code writing messages through `IMessageContainer` |
| **Inputs** | Property name and message text |
| **Outputs** | Populated `ModelStateDictionary`, `Warnings`, `Informationals` |
| **Primary components** | `ModelStateWrapper.AddError`, `AddWarning`, `AddInformation` |
| **Entry point** | `src/Web.Mvc/Classes/ModelStateWrapper.cs` |

## Steps

1. `AddError` — when the same message text already exists on any model-state entry (case-insensitive), replace the message with `string.Empty` before adding, so the text is displayed once even when several properties are in error; then call `modelState.AddModelError(propertyName, message)`. The model-state entry is still created, so field-level highlighting still works ([BR-37](../business-rules.md#br-37-duplicate-error-message-displayed-once-but-still-flags-the-field)).
2. `AddWarning` — append only when no case-insensitive duplicate exists in `Warnings` ([BR-38](../business-rules.md#br-38-duplicate-warnings-and-informational-messages-are-suppressed)).
3. `AddInformation` — append only when no case-insensitive duplicate exists in `Informationals` ([BR-38](../business-rules.md#br-38-duplicate-warnings-and-informational-messages-are-suppressed)).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Message written via IMessageContainer])
	Kind{Error, Warning, or Information?}
	ErrDup{Duplicate error text?}
	ErrBlank[Add with blank message]
	ErrFull[Add model error with full text]
	WarnDup{Duplicate warning/info?}
	Suppress([Suppress duplicate])
	Append([Append message])
	Start --> Kind
	Kind -->|Error| ErrDup
	ErrDup -->|Yes| ErrBlank
	ErrDup -->|No| ErrFull
	Kind -->|Warning/Info| WarnDup
	WarnDup -->|Yes| Suppress
	WarnDup -->|No| Append
```

## Failure and edge-case behavior

- No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `src/Web.Mvc/Classes/ModelStateWrapper.cs`
