-
Notifications
You must be signed in to change notification settings - Fork 2.1k
AttemptedValueIsInvalidAccessor on nullable types results in "Nullable`1." message #6076
Comments
IIRC we set this message up to mimic a similar message in MVC 5.x. But, I agree the message only helps users fix their submission if the value Might want to expand on this and look at other errors we add to |
Yeah I think the property display name (or parameter display name in this case) should be used in the error message. The type names shouldn't leak out. Don't care what previous versions of MVC did. So the question is, do we have this metadata available at the point the error is created? @dougbu can you take a look? |
@Eilon / @rynowak we shouldn't change the error to It's only in the specific case of a parameter that the error mentions a type name and there's nothing better to use in that case. (Same thing probably happens for elements of a collection property but, again, there's nothing better to use then.) However, the error could mention If we go this way, I lean toward creating a new |
Of course I meant |
Can we use the key (model-name)? |
Since the original report was about a conversion error and the browser must have submitted something with the That said, That that said, the even-more general (still corner) cases include a top-level array or generic type. My suggestion to use @Eilon thoughts? |
Per discussion with @dougbu :
|
Experimented a bit and found a fair number of cases where error messages in
|
- #6076 - add resources and accessors specifically for the element / parameter cases - avoid `metadata.GetDisplayName()` where possible - fill in the `ValidationContext` that `ValidatorObjectAdapter` uses - e.g. `Validate_NestedComplexType_IValidatableObject_Invalid()` test fails without this Possible future work: - improve error message used for `ModelMetadata.IsRequired` elements and parameters - use something besides the type for `ValidationContext.DisplayName` of elements and parameters nits: - trailing whitespace - use more `out var`
- #6076 - add resources and accessors specifically for the element / parameter cases - avoid `metadata.GetDisplayName()` where possible - fill in the `ValidationContext` that `ValidatorObjectAdapter` uses - e.g. `Validate_NestedComplexType_IValidatableObject_Invalid()` test fails without this Possible future work: - improve error message used for `ModelMetadata.IsRequired` elements and parameters - use something besides the type for `ValidationContext.DisplayName` of elements and parameters nits: - trailing whitespace - use more `out var`
a90f411 addresses the original reported problem and |
Given the following where MyEnum is an optional value, where the default is null:
And providing the query string with an invalid value (e.g.
?myE=asd
) the request will fail via theModelBindingMessageProvider
andAttemptedValueIsInvalidAccessor
; where the message isThe value '{0}' is not valid for {1}.
.However, with a nullable type, the
{1}
results in the message:I see a work around using localisation on the message, but should the message not attempt to find the underlying Type rather than the nullable?
Is this loosely related to #2985?
The text was updated successfully, but these errors were encountered: