Sorry for the long question/request...
I'm running into an exception during a TelerikScheduler Edit event when trying to initialize the model. I believe this is occurring because the models are complex objects with another object as a property inside it, where the "submodel" does not have a parameterless constructor. I'm receiving the following exception while debugging:
I read this ticket that discusses a similar issue as well as this ticket which describes the OnModelInit event that allows you to create an instance of the model to pass to the CUD event. However, after implementing the OnModelInit handler the error is still occurring because it is trying to clone that object before passing it to the edit event and is attempting to use a constructor with no parameters which does not exist.
To reiterate the ticket above, it would be nice if the clone process checks to see if the model implements the ICloneable interface. This will allow custom clone behavior which should resolve this issue. Or is there already a fix/workaround for this?
I added a few simplified code segments below as an example of the issue I'm having... (I'm using Blazor Server if that's relevant)
Index.razor:
@page "/"
@using TelerikBlazorTestApp.Models
<TelerikScheduler Data="@Appointments"
AllowCreate="true" AllowDelete="true" AllowUpdate="true"
OnModelInit="@ModelInitHandler">
<SchedulerViews>
<SchedulerDayView />
<SchedulerWeekView />
<SchedulerMonthView />
</SchedulerViews>
</TelerikScheduler>
@code {
public List<SchedulerAppointment<TestModel>> Appointments { get; set; }
protected override async Task OnInitializedAsync()
{
Appointments = new List<SchedulerAppointment<TestModel>>()
{
new SchedulerAppointment<TestModel> { Title = "Test 1", Start = DateTime.Now, End = DateTime.Now.AddHours(1), IsAllDay = false, Model = new TestModel("blah") },
new SchedulerAppointment<TestModel> { Title = "Test 2", Start = DateTime.Now.AddHours(1), End = DateTime.Now.AddHours(2), IsAllDay = false, Model = new TestModel("blah") },
new SchedulerAppointment<TestModel> { Title = "Test 3", Start = DateTime.Now, End = DateTime.Now, IsAllDay = true, Model = new TestModel("blah") }
};
}
public SchedulerAppointment<TestModel> ModelInitHandler()
{
return new SchedulerAppointment<TestModel>("blah");
}
}
SchedulerAppointment.cs:
namespace TelerikBlazorTestApp.Models
{
public class SchedulerAppointment<TItem>
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public bool IsAllDay { get; set; }
public string RecurrenceRule { get; set; }
public List<DateTime> RecurrenceExceptions { get; set; }
public Guid? RecurrenceId { get; set; }
public TItem Model { get; set; }
public SchedulerAppointment()
{
Id = Guid.NewGuid();
}
public SchedulerAppointment(string s)
{
Id = Guid.NewGuid();
Model = (TItem)Activator.CreateInstance(typeof(TItem), s);
}
}
}
namespace TelerikBlazorTestApp.Models { public class TestModel { public string PropA { get; set; } public string PropB { get; set; } public TestModel(string s) { // something using s here } } }
Thanks!