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
ModelStateDictionaryvalidation errors into JSON-friendlyErrorViewModel[]correlated back to grid rows, and the inverse: loading a domainIValidationResultintoModelStateDictionary. - 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 |
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–BR-36. |
| GetErrors |
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–BR-36. |
Sources¶
src/Web.Mvc/Extensions/ModelStateExtensions.cs