ModelStateDictionary.TryAddModelException(String, Exception) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
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.