簡體   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]'

我正在嘗試使用從 API 獲取的數據填充 Telerik Blazor 調度程序 UI 組件。我收到的錯誤消息是:

錯誤:System.AggregateException:發生一個或多個錯誤。 (無法將“System.String”類型的 object 轉換為類型“System.Collections.Generic.IEnumerable`1[System.DateTime]”。)

---> System.InvalidCastException:無法將“System.String”類型的 object 轉換為類型“System.Collections.Generic.IEnumerable`1[System.DateTime]”。

在 Telerik.Blazor.Components.TelerikScheduler`1.CreateAppointment(TItem 數據項)

在 Telerik.Blazor.Components.TelerikScheduler`1.ExpandAppointments()

在 Telerik.Blazor.Components.TelerikScheduler`1.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 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; }
}

屬性public string RecurrenceExceptions { get; set; } public string RecurrenceExceptions { get; set; } 在你的public string RecurrenceExceptions { get; set; } class 應該是一個List<DateTime>類型而不是一個string

來自 Telerik:

RecurrenceExceptions List 重復約會的例外列表。 它告訴調度程序何時跳過呈現重復約會,因為它的實例被顯式更改或移除(刪除),因此它是重復規則的例外。 另請參閱下面的注釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM