syncfusion blazor 22.1.34
when selecting an appointment console shows the following error:
System.InvalidCastException: Specified cast is not valid.
at Syncfusion.Blazor.PropertyAccessor`2[[SP.Client.Pages.Scheduler.Reservation, SP.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Boolean, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetValue(Object source)
at Syncfusion.Blazor.PropertyAccessorProvider.GetValue(Object obj, String propertyName)
at Syncfusion.Blazor.ReflectionHelper`1[[SP.Client.Pages.Scheduler.ReservationDataTemplate, SP.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetValue(ReservationDataTemplate obj, String propertyName)
at Syncfusion.Blazor.Schedule.SfSchedule`1[[SP.Client.Pages.Scheduler.ReservationDataTemplate, SP.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetValue(String fieldName, ReservationDataTemplate obj)
at Syncfusion.Blazor.Schedule.Internal.EventBase`1[[SP.Client.Pages.Scheduler.ReservationDataTemplate, SP.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].NonGenericConversion(IEnumerable`1 eventsData, Boolean isPreventActualDataUpdate, Boolean isPreventConversion)
my page look like the following
<SfSchedule CssClass="block-events" TValue="ReservationDataTemplate" @bind-CurrentView="@CurrentView" @bind-SelectedDate="@SelectedDate" Width="100%" Height="100%">
<ScheduleGroup Resources="@groupData" EnableCompactView="false" />
<ScheduleResources>
<ScheduleResource TItem="StaffSnapshot"
TValue="Guid[]"
DataSource="@Staffs"
Field="@nameof(ReservationDataTemplate.StaffId)"
Title="testName"
Name="Staffs"
TextField="@nameof(StaffSnapshot.Name)"
IdField="@nameof(StaffSnapshot.Id)"
ColorField="@nameof(StaffSnapshot.Color)"
AllowMultiple="false" />
</ScheduleResources>
<ScheduleEventSettings DataSource="@Reservations" />
<ScheduleViews>
<ScheduleView Option="View.TimelineDay"></ScheduleView>
</ScheduleViews>
</SfSchedule>
@code {
private DateTime SelectedDate { get; set; } = DateTime.Now;
private View CurrentView { get; set; } = View.TimelineDay;
private string[] groupData = new string[] { "Staffs" };
public List<StaffSnapshot> Staffs { get; set; }
public List<ReservationDataTemplate> Reservations { get; set; }
protected override async Task OnInitializedAsync()
{
Staffs = new List<StaffSnapshot>()
{
new StaffSnapshot
{
Name = "test1",
Id = Guid.NewGuid(),
Color = "#1aaa55"
},
new StaffSnapshot
{
Name = "test2",
Id = Guid.NewGuid(),
Color = "#1aaa55"
}
};
Reservations = new List<ReservationDataTemplate>()
{
new Reservation
{
Id = Guid.NewGuid(),
StartTime = DateTime.Now,
EndTime = DateTime.Now + new TimeSpan(1,0,0),
StaffId = Staffs[0].Id
},
new Reservation
{
Id = Guid.NewGuid(),
StartTime = DateTime.Now,
EndTime = DateTime.Now + new TimeSpan(1,0,0),
StaffId = Staffs[1].Id
}
};
StateHasChanged();
}
public class ReservationDataTemplate
{
public Guid Id { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public virtual bool IsBlock { get; set; }
public Guid StaffId { get; set; }
}
public class Reservation : ReservationDataTemplate
{
public override bool IsBlock { get; set; } = false;
}
public class StaffSnapshot
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Color { get; set; } = "";
public int GroupId { get; set; } = 0;
}
}
Hi Chen,
We've examined your query using the provided sample, and we want to let you know
that you should define the same type of Appointment class as Scheduler 'Tvalue'
or create appointments using Appointment class based on the assigned Scheduler
'Tvalue.' This approach might resolve the issue you mentioned. In your case,
you've defined scheduler 'Tvalue' as 'ReservationDataTemplate' but created
appointments with the 'Reservation' class, which could lead to the casting
issue you described. We also recommend using Resource ‘Tvalue' as 'Guid'
instead of 'Guid[]' since you've set 'AllowMultiple' to false. Try our shared
sample and let us know if you need any further assistance.
[Index.Razor]
|
<SfSchedule CssClass="block-events" TValue="Reservation" @bind-CurrentView="@CurrentView" @bind-SelectedDate="@SelectedDate" Width="100%" Height="100%">
<ScheduleGroup Resources="@groupData" EnableCompactView="false" />
<ScheduleResources>
<ScheduleResource TItem="StaffSnapshot" TValue="Guid" DataSource="@Staffs" Field="@nameof(ReservationDataTemplate.StaffId)" Title="testName" Name="Staffs" TextField="@nameof(StaffSnapshot.Name)" IdField="@nameof(StaffSnapshot.Id)" ColorField="@nameof(StaffSnapshot.Color)" AllowMultiple="false" />
</ScheduleResources>
<ScheduleEventSettings DataSource="@Reservations" />
<ScheduleViews>
<ScheduleView Option="View.TimelineDay"></ScheduleView>
</ScheduleViews>
</SfSchedule>
@code {
private DateTime SelectedDate { get; set; } = DateTime.Now;
private View CurrentView { get; set; } = View.TimelineDay;
private string[] groupData = new string[] { "Staffs" };
public List<StaffSnapshot> Staffs { get; set; }
public List<ReservationDataTemplate> Reservations { get; set; }
protected override async Task OnInitializedAsync()
{
Staffs = new List<StaffSnapshot>()
{
new StaffSnapshot
{
Name = "test1",
Id = Guid.NewGuid(),
Color = "#1aaa55"
},
new StaffSnapshot
{
Name = "test2",
Id = Guid.NewGuid(),
Color = "#1aaa55"
}
};
Reservations = new List<ReservationDataTemplate>()
{
new Reservation
{
Id = Guid.NewGuid(),
StartTime = DateTime.Now,
EndTime = DateTime.Now + new TimeSpan(1,0,0),
StaffId = Staffs[0].Id
},
new Reservation
{
Id = Guid.NewGuid(),
StartTime = DateTime.Now,
EndTime = DateTime.Now + new TimeSpan(1,0,0),
StaffId = Staffs[1].Id
}
};
StateHasChanged();
} } |
Regards,
Venkatesh
It worked, thanks!!
Hi Chen,
Regards,
Satheesh Kumar B