[英]Blazor Telerik Scheduler - Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IEnumerable`1[System.DateTime]'
I'm trying to populate a Telerik Blazor Scheduler UI Component with data I'm fetching from my API. The error message I'm getting is:我正在尝试使用从 API 获取的数据填充 Telerik Blazor 调度程序 UI 组件。我收到的错误消息是:
Error: System.AggregateException: One or more errors occurred.
错误:System.AggregateException:发生一个或多个错误。 (Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IEnumerable`1[System.DateTime]'.)
(无法将“System.String”类型的 object 转换为类型“System.Collections.Generic.IEnumerable`1[System.DateTime]”。)
---> System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IEnumerable`1[System.DateTime]'.
---> System.InvalidCastException:无法将“System.String”类型的 object 转换为类型“System.Collections.Generic.IEnumerable`1[System.DateTime]”。
at Telerik.Blazor.Components.TelerikScheduler`1.CreateAppointment(TItem dataItem)
在 Telerik.Blazor.Components.TelerikScheduler`1.CreateAppointment(TItem 数据项)
at Telerik.Blazor.Components.TelerikScheduler`1.ExpandAppointments()
在 Telerik.Blazor.Components.TelerikScheduler`1.ExpandAppointments()
at Telerik.Blazor.Components.TelerikScheduler`1.ProcessAppointmentsAsync()
在 Telerik.Blazor.Components.TelerikScheduler`1.ProcessAppointmentsAsync()
at Telerik.Blazor.Components.TelerikScheduler`1.OnAfterRenderAsync(Boolean firstRender)
在 Telerik.Blazor.Components.TelerikScheduler`1.OnAfterRenderAsync(布尔 firstRender)
--- End of inner exception stack trace ---
--- 内部异常堆栈跟踪结束 ---
Unsure about the work around for this.不确定这方面的工作。 Below is my code:
下面是我的代码:
@if (HolidayPlanners != null)
{
<pre>
TelerikScheduler Data="@HolidayPlanners" @bind-Date="@StartDate" @bind-View="@selectedView" Height="100%" Class="Scheduler"
OnUpdate="@UpdateAppointment"
OnCreate="@AddAppointment"
OnDelete="@DeleteAppointment"
AllowCreate="true"
AllowDelete="true"
AllowUpdate="true"
IdField="@(nameof(UvwHolidayPlanner.Pk))"
StartField="@(nameof(UvwHolidayPlanner.StartDate))"
EndField="@(nameof(UvwHolidayPlanner.EndDate))"
TitleField="@(nameof(UvwHolidayPlanner.Title))"
DescriptionField="@(nameof(UvwHolidayPlanner.Description))"
IsAllDayField="@(nameof(UvwHolidayPlanner.IsAllDay))"
RecurrenceRuleField="@(nameof(UvwHolidayPlanner.RecurrenceRule))"
RecurrenceExceptionsField="@(nameof(UvwHolidayPlanner.RecurrenceExceptions))"
RecurrenceIdField="@(nameof(UvwHolidayPlanner.RecurrenceFk))">
SchedulerViews
SchedulerMonthView/SchedulerMonthView
/SchedulerViews
/TelerikScheduler
</pre>
}
@code {
public string _URL = String.Empty;
IEnumerable<UvwHolidayPlanner> HolidayPlanners { get; set; }
DateTime StartDate = DateTime.Now;
SchedulerView selectedView { get; set; } = SchedulerView.Month;
protected override async Task OnInitializedAsync()
{
_URL = settingsAccessor.AllClientSettings().BaseServiceURI;
HolidayPlanners = (await http.CreateClient("ClientSettings").GetFromJsonAsync<List<UvwHolidayPlanner>>($"{_URL}/api/lookup/HolidayPlanner"))
.OrderBy(t => t.Title)
.ToList();
StateHasChanged();
}
void UpdateAppointment(SchedulerUpdateEventArgs args)
{
//appointmentService.UpdateAppointment((AppointmentDto)args.Item);
}
void AddAppointment(SchedulerCreateEventArgs args)
{
//appointmentService.CreateAppointment((AppointmentDto)args.Item);
}
void DeleteAppointment(SchedulerDeleteEventArgs args)
{
//appointmentService.DeleteAppointment((AppointmentDto)args.Item);
}
}
Below is UvwHoldidayPlanner class:下面是 UvwHoldidayPlanner class:
public class UvwHolidayPlanner
{
public int Pk { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public bool IsAllDay { get; set; }
public string RecurrenceRule { get; set; }
public int RecurrenceFk { get; set; }
public string RecurrenceExceptions { get; set; }
public string StartTimezone { get; set; }
public string EndTimezone { get; set; }
}
The property public string RecurrenceExceptions { get; set; }
属性
public string RecurrenceExceptions { get; set; }
public string RecurrenceExceptions { get; set; }
public string RecurrenceExceptions { get; set; }
in your UvwHolidayPlanner class should be a List<DateTime>
type and not a string
.在你的
public string RecurrenceExceptions { get; set; }
class 应该是一个List<DateTime>
类型而不是一个string
。
From Telerik:来自 Telerik:
RecurrenceExceptions List A list of exceptions for a recurring appointment.
RecurrenceExceptions List 重复约会的例外列表。 It tells the Scheduler when to skip rendering a recurring appointment because its instance is explicitly changed or removed (deleted), and so it is an exception to the recurrence rule.
它告诉调度程序何时跳过呈现重复约会,因为它的实例被显式更改或移除(删除),因此它是重复规则的例外。 Also see the note below.
另请参阅下面的注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.