Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need more detail on using TypeConverters in ASP.NET Core #11820

Closed
Tracked by #16319
davisnw opened this issue Apr 4, 2019 — with docs.microsoft.com · 3 comments
Closed
Tracked by #16319

Need more detail on using TypeConverters in ASP.NET Core #11820

davisnw opened this issue Apr 4, 2019 — with docs.microsoft.com · 3 comments
Labels
doc-enhancement Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link

davisnw commented Apr 4, 2019

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.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added the Source - Docs.ms Docs Customer feedback via GitHub Issue label Apr 4, 2019
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Apr 4, 2019
@TjeuKayim
Copy link

Can dependency injection be used to register a TypeConverter, instead of the static TypeDescriptor.AddAttributes()?

https://stackoverflow.com/q/43378709

@Rick-Anderson
Copy link
Contributor

Rick-Anderson commented Dec 26, 2019

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 TypeConverters 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:

  • support thousands separators in received strings for decimal, double and float values unless FloatingPointTypeModelBinderProvider is removed from MvcOptions.ModelBinderProviders
  • disallow binding undefined integer values to an enum unless EnumTypeModelBinderProvider is removed from MvcOptions.ModelBinderProviders

/cc @pranavkm in case you have something to add

@Rick-Anderson
Copy link
Contributor

Moved to Master issue #16319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

5 participants