ModelStateDictionary.TryAddModelException(String, Exception) Method

Definition

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

public:
 bool TryAddModelException(System::String ^ key, Exception ^ exception);
public bool TryAddModelException (string key, Exception exception);
member this.TryAddModelException : string * Exception -> bool
Public Function TryAddModelException (key As String, exception As Exception) As Boolean

Parameters

key
String

The key of the ModelStateEntry to add errors to.

exception
Exception

The Exception to add.

Returns

True if the given error was added, false if the error was ignored. See MaxAllowedErrors.

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). Where ModelMetadata is available, use AddModelError(String, Exception, ModelMetadata) instead.

Applies to