Table of Contents

Class ModelStateExtensions

Namespace
SEBT.Portal.Kernel.AspNetCore
Assembly
SEBT.Portal.Kernel.AspNetCore.dll

Provides extension methods for working with the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary class to map ValidationError to the appropriate structure for HTTP response.

public static class ModelStateExtensions
Inheritance
object
ModelStateExtensions

Methods

AddModelErrors(ModelStateDictionary, IEnumerable<ValidationError>)

Adds multiple validation errors to the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary using the keys specified by each error.

public static void AddModelErrors(this ModelStateDictionary modelState, IEnumerable<ValidationError> errors)

Parameters

modelState ModelStateDictionary

The Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary instance where errors will be added.

errors IEnumerable<ValidationError>

The collection of ValidationError objects to add to the model state.

AddModelErrors(ModelStateDictionary, string, IEnumerable<ValidationError>)

Adds multiple validation errors to the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary for a specified key.

public static void AddModelErrors(this ModelStateDictionary modelState, string key, IEnumerable<ValidationError> errors)

Parameters

modelState ModelStateDictionary

The Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary instance where errors will be added.

key string

The key to associate with each of the validation errors.

errors IEnumerable<ValidationError>

The collection of ValidationError objects to add to the model state.

ToModelState(IEnumerable<ValidationError>)

Converts a collection of ValidationError objects to a populated Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.

public static ModelStateDictionary ToModelState(this IEnumerable<ValidationError> errors)

Parameters

errors IEnumerable<ValidationError>

The collection of ValidationError objects to add to the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.

Returns

ModelStateDictionary

A Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary instance containing the specified validation errors.