In the attached files, there is a DataGrid that has two DateTimePickers. 2-way binding is configured, but not working correctly. You can change the date and time values, but as soon as you click on save the modal dialog stays open and all the values in the dialog reset.
Example:
Before changing data:
Change date/time:
Click on SAVE:
Message "One or more errors occurred. (One or more errors occurred. (Cannot convert the literal '2021-08-26T00:00:00' to the expected type 'Edm.DateTimeOffset'.))"
<div class="form-row">
<div class="form-group col-md-6">
<label class="e-label-top">Start Date</label>
<SfDatePicker TValue="DateTime"
@bind-Value="@Training.StartDate"
AllowEdit="true"
Format="MM/dd/yy HH:mm tt">
</SfDatePicker>
</div>
<div class="form-group col-md-6">
<label class="e-label-top">End Date</label>
<SfDateTimePicker TValue="DateTime"
@bind-Value="@Training.EndDate">
</SfDateTimePicker>
</div>
</div>
|
Made the changes above, but that did not resolve the issue. Blazor is expecting a Edm.DateTimeOffset value, and the control is sending a literal DateTime value.
Here is the controller code:
[HttpPatch("Training({id})")]
public async Task
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var training = await _itssMasterContext
.Training
.FirstOrDefaultAsync(e => e.Id == id
);
if (training == null)
{
return NotFound();
}
patch.Patch(training);
await _itssMasterContext.SaveChangesAsync();
return NoContent();
}
The exception gets thrown here:
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
The Exception is:
One or more errors occurred. (One or more errors occurred. (Cannot convert the literal '2021-08-30T09:10:00' to the expected type 'Edm.DateTimeOffset'.))
Stack trace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.AspNetCore.OData.Formatter.Wrapper.ODataReaderExtensions.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.AspNetCore.OData.Formatter.Deserialization.ODataResourceDeserializer.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.AspNetCore.OData.Formatter.ODataInputFormatter.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.OData.Formatter.ODataInputFormatter.LoggerError(HttpContext context, Exception ex)
at Microsoft.AspNetCore.OData.Formatter.ODataInputFormatter.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.OData.Formatter.ODataInputFormatter.