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 #1723

Open
mwinkler opened this Issue Nov 25, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@mwinkler

mwinkler commented Nov 25, 2018

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

This comment has been minimized.

SQL-MisterMagoo commented Nov 25, 2018

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

This comment has been minimized.

SQL-MisterMagoo commented Nov 25, 2018

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

This comment has been minimized.

mwinkler commented Nov 29, 2018

Is there a way to register such conversion in general?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment