No examples are given on how to create a TypeConverter, and it is unclear how to write the TypeConverter to give an informative message when binding fails. E,g., if I had a custom "Date" type, and the provided value is "Bob", how should that be communicated from the TypeConverter implementation? In the custom modelbinder, you have access to ModelState, but not so in the TypeConverter.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Can dependency injection be used to register a TypeConverter
, instead of the static TypeDescriptor.AddAttributes()
?
Request to PU: Provide a TypeConverter
sample.
Per @dougbu
in this comment in #17002
ASP.NET Core doesn't special-case DateTime
values at all; binding is done using the default TypeConverter
for the type. This is the same for most simple types though we add special cases for decimal
, double
, enum
, and float
. The details should already be described in the .NET and .NET Core docs.
If we don't already cover fact TypeConverter
s are used in model binding, that might be worth documenting somewhere so readers know where to look for supported formats. And, if we take the time to do that, might also mention the following special cases:
decimal
, double
and float
values unless FloatingPointTypeModelBinderProvider
is removed from MvcOptions.ModelBinderProviders
enum
unless EnumTypeModelBinderProvider
is removed from MvcOptions.ModelBinderProviders
/cc @pranavkm in case you have something to add
Moved to Master issue #16319
Most helpful comment
Can dependency injection be used to register a
TypeConverter
, instead of the staticTypeDescriptor.AddAttributes()
?https://stackoverflow.com/q/43378709