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
-
objectModelStateExtensions
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
modelStateModelStateDictionaryThe Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary instance where errors will be added.
errorsIEnumerable<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
modelStateModelStateDictionaryThe Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary instance where errors will be added.
keystringThe key to associate with each of the validation errors.
errorsIEnumerable<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
errorsIEnumerable<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.