Blazor Telerik 计划程序 - 无法将类型 'System.String' 的对象强制转换为类型 'System.Collections.Generic.IEnumerable`1[



我试图填充一个teleerik Blazor Scheduler UI组件与数据我从我的API抓取。我得到的错误信息是:

错误:系统。AggregateException:发生了一个或多个错误。无法强制转换"System"类型的对象。String' to type 'System.Collections.Generic.IEnumerable ' 1[System.DateTime]'.)

——比;系统。InvalidCastException:无法强制转换系统类型的对象。字符串'类型'System.Collections.Generic.IEnumerable ' 1[System.DateTime]'.

Telerik.Blazor.Components.TelerikScheduler的1。CreateAppointment (TItem dataItem)

1. Telerik.Blazor.Components.TelerikScheduler"expandappointments ()

1. Telerik.Blazor.Components.TelerikScheduler"processappointmentsasync ()

Telerik.Blazor.Components.TelerikScheduler的1。OnAfterRenderAsync(布尔firstRender)

——内部异常堆栈跟踪结束——

不确定如何解决这个问题。下面是我的代码:

@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);
}
}

下面是UvwHoldidayPlanner类:

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; }
}

属性public string RecurrenceExceptions { get; set; }在你的UvwHolidayPlanner类应该是一个List<DateTime>类型,而不是string

从Telerik:

RecurrenceExceptions List反复出现的约会。它告诉Scheduler何时跳过渲染重复约会,因为其实例被显式更改或移除(删除),因此它是递归规则的例外。

相关内容

最新更新