简体   繁体   English

Blazor Telerik 计划程序 - 无法将类型为“System.String”的 object 转换为类型“System.Collections.Generic.IEnumerable`1[System.DateTime]”

[英]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.

相关问题 无法将类型为“ System.Collections.ArrayList”的对象转换为类型为“ System.Collections.Generic.IEnumerable” - Unable to cast object of type 'System.Collections.ArrayList' to type 'System.Collections.Generic.IEnumerable' 无法将类型为“ System.Data.Entity.Infrastructure.DbQuery`1 []”的对象转换为类型为“ System.Collections.Generic.IEnumerable”的对象 - Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[]' to type 'System.Collections.Generic.IEnumerable 无法将“System.Linq.OrderedEnumerable`2[***]”类型的对象转换为“System.Collections.Generic.IEnumerable`1[***]” - Unable to cast object of type 'System.Linq.OrderedEnumerable`2[***]' to type 'System.Collections.Generic.IEnumerable`1[***]' 无法将类型为“ System.Data.SqlClient.SqlDataReader”的对象转换为类型为“ System.Collections.Generic.IEnumerable” - Unable to cast object of type 'System.Data.SqlClient.SqlDataReader' to type 'System.Collections.Generic.IEnumerable' 无法将“System.String”类型的对象转换为“System.Collections.Generic.List`1[System.String]”类型 - Unable to cast object of type 'System.String' to type 'System.Collections.Generic.List`1[System.String]' 无法将类型为“ System.DateTime”的对象转换为类型为“ System.String”的对象 - Unable to cast object of type 'System.DateTime' to type 'System.String' 无法将“System.DateTime”类型的对象转换为“System.String”类型。 C# - Unable to cast object of type 'System.DateTime' to type 'System.String'. c# Linq“无法将‘System.DateTime’类型的对象转换为‘System.String’类型”错误 - Linq "Unable to cast object of type 'System.DateTime' to type 'System.String'" error Datecolumn:无法将“System.DateTime”类型的对象强制转换为“System.String”类型 - Datecolumn: Unable to cast object of type 'System.DateTime' to type 'System.String' 从Excel加载DataTable:无法将类型为“ System.DateTime”的对象转换为类型为“ System.String”的对象 - Loading DataTable from Excel: Unable to cast object of type 'System.DateTime' to type 'System.String'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM