ModelStateDictionaryExtensions.TryAddModelException<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception) Method

Definition

Adds the specified exception to the Errors instance that is associated with the specified expression. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

public:
generic <typename TModel>
[System::Runtime::CompilerServices::Extension]
 static void TryAddModelException(Microsoft::AspNetCore::Mvc::ModelBinding::ModelStateDictionary ^ modelState, System::Linq::Expressions::Expression<Func<TModel, System::Object ^> ^> ^ expression, Exception ^ exception);
public static void TryAddModelException<TModel> (this Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary modelState, System.Linq.Expressions.Expression<Func<TModel,object>> expression, Exception exception);
static member TryAddModelException : Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary * System.Linq.Expressions.Expression<Func<'Model, obj>> * Exception -> unit
<Extension()>
Public Sub TryAddModelException(Of TModel) (modelState As ModelStateDictionary, expression As Expression(Of Func(Of TModel, Object)), exception As Exception)

Type Parameters

TModel

The type of the model.

Parameters

modelState
ModelStateDictionary

The ModelStateDictionary instance this method extends.

expression
Expression<Func<TModel,Object>>

An expression to be evaluated against an item in the current model.

exception
Exception

The Exception to add.

Remarks

This method allows adding the exception to the current ModelStateDictionary when ModelMetadata is not available or the exact exception must be maintained for later use (even if it is for example a FormatException).

Applies to