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

'bind' does not accept values of type System.DateTimeOffset #5651

Closed
mwinkler opened this issue Nov 25, 2018 · 5 comments
Closed

'bind' does not accept values of type System.DateTimeOffset #5651

mwinkler opened this issue Nov 25, 2018 · 5 comments
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one
Milestone

Comments

@mwinkler
Copy link

If I try to bind the type System.DateTimeOffset I get a

System.ArgumentException: 'bind' does not accept values of type System.DateTimeOffset. To read and write this value type, wrap it in a property of type string with suitable getters and setters.

Example:

<input type="date" class="form-control" bind=@Timestamp />

@SQL-MisterMagoo
Copy link
Contributor

This is because <input> takes a string value and there is no correct default way to convert between string and DateTimeOffset - at least not one that would suit everyone.

The wrapper you need would look something like this

DateTimeOffset _timeStamp;

string Timestamp 
{
  get
  {
    return _timeStamp?.ToString("<some format string>");
  }
  set
  {
    DateTimeOffset.TryParse(value, ... ,out _timeStamp);
  }
}

@SQL-MisterMagoo
Copy link
Contributor

An additional benefit of a wrapper is, of course, that you can add code to call Actions on parent controls or State to notify them of a change.

@mwinkler
Copy link
Author

Is there a way to register such conversion in general?

@aspnet-hello aspnet-hello transferred this issue from dotnet/blazor Dec 17, 2018
@aspnet-hello aspnet-hello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-blazor Includes: Blazor, Razor Components labels Dec 17, 2018
@danroth27 danroth27 added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Apr 12, 2019
@danroth27 danroth27 added this to the 3.0.0-preview6 milestone Apr 12, 2019
@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@mkArtakMSFT
Copy link
Member

Related issue: #9598

@mkArtakMSFT
Copy link
Member

This is already supported.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

5 participants