---
title: ModelStateExtensions
summary: API reference for ModelStateExtensions.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-09-17
library: SAIF.Framework.Web.Mvc
reference_type: package
---

# ModelStateExtensions

Translates ASP.NET `ModelStateDictionary` validation errors into JSON-friendly `ErrorViewModel[]` correlated back to grid rows, and the inverse: loading a domain `IValidationResult` into `ModelStateDictionary`.

## Purpose
- Translates ASP.NET `ModelStateDictionary` validation errors into JSON-friendly `ErrorViewModel[]` correlated back to grid rows, and the inverse: loading a domain `IValidationResult` into `ModelStateDictionary`.
- The grid-row correlation logic is the most complex part of this library's model-state handling; see the "Project model-state errors into view models" operation for the full key-normalization algorithm.

## Context
- Namespace: `SAIF.Web.Mvc`
- Assembly/package: `SAIF.Framework.Web.Mvc (source-shipping NuGet package)`
- Kind: static class

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| LoadValidationErrors(ModelStateDictionary, IValidationResult) | `public static void LoadValidationErrors(this ModelStateDictionary modelState, IValidationResult result)` | Adds one model error per validation-result error, using its `PropertyName` and `ErrorMessage`. |
| GetErrors(this ModelStateDictionary) | `public static ErrorViewModel[] GetErrors(this ModelStateDictionary modelState)` | Projects all model-state errors with grid-row correlation disabled (always returns `""` for `GridRowId`). |
| GetErrors<TGridRow,TProperty>(ModelStateDictionary, Expression<Func<GridViewModel<TGridRow>>>, Expression<Func<TGridRow,TProperty>>) | `public static ErrorViewModel[] GetErrors<TGridRow, TProperty>(this ModelStateDictionary modelState, Expression<Func<GridViewModel<TGridRow>>> gridProperty, Expression<Func<TGridRow, TProperty>> rowIdProperty)` | Projects model-state errors correlated to a single grid, using the supplied grid-property and row-id lambda pair; see [BR-34](../../business-rules.md#br-34-pending-change-grid-keys-are-not-correlated-to-a-row)–[BR-36](../../business-rules.md#br-36-error-keys-are-dom-safe). |
| GetErrors<TGridRow,TProperty>(ModelStateDictionary, params GridErrorArguments<TGridRow,TProperty>[]) | `public static ErrorViewModel[] GetErrors<TGridRow, TProperty>(this ModelStateDictionary modelState, params GridErrorArguments<TGridRow, TProperty>[] gridTranslators)` | Projects model-state errors correlated across multiple grids via an array of grid/row-id translators; see [BR-34](../../business-rules.md#br-34-pending-change-grid-keys-are-not-correlated-to-a-row)–[BR-36](../../business-rules.md#br-36-error-keys-are-dom-safe). |

## Sources
- `src/Web.Mvc/Extensions/ModelStateExtensions.cs`
