Share via


ModelStateDictionary.TryAddModelError Method

Definition

Overloads

TryAddModelError(String, Exception, ModelMetadata)

Attempts to add 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.

TryAddModelError(String, String)

Attempts to add the specified errorMessage 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.

TryAddModelError(String, Exception, ModelMetadata)

Source:
ModelStateDictionary.cs
Source:
ModelStateDictionary.cs
Source:
ModelStateDictionary.cs

Attempts to add 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 TryAddModelError(System::String ^ key, Exception ^ exception, Microsoft::AspNetCore::Mvc::ModelBinding::ModelMetadata ^ metadata);
public bool TryAddModelError (string key, Exception exception, Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata metadata);
member this.TryAddModelError : string * Exception * Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata -> bool
Public Function TryAddModelError (key As String, exception As Exception, metadata As ModelMetadata) As Boolean

Parameters

key
String

The key of the ModelStateEntry to add errors to.

exception
Exception

The Exception to add. Some exception types will be replaced with a descriptive error message.

metadata
ModelMetadata

The ModelMetadata associated with the model.

Returns

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

Applies to

TryAddModelError(String, String)

Source:
ModelStateDictionary.cs
Source:
ModelStateDictionary.cs
Source:
ModelStateDictionary.cs

Attempts to add the specified errorMessage 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 TryAddModelError(System::String ^ key, System::String ^ errorMessage);
public bool TryAddModelError (string key, string errorMessage);
member this.TryAddModelError : string * string -> bool
Public Function TryAddModelError (key As String, errorMessage As String) As Boolean

Parameters

key
String

The key of the ModelStateEntry to add errors to.

errorMessage
String

The error message to add.

Returns

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

Applies to