ModelStateDictionary.TryAddModelException(String, Exception) Method
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
- key
- String
The key of the ModelStateEntry to add errors to.
True
if the given error was added, false
if the error was ignored.
See MaxAllowedErrors.
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.
Product | Versions |
---|---|
ASP.NET Core | 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0 |