I have created a custom editor template for my scheduler, and it works fine except for one glaring issue. When I update the list of attendees for a given meeting, the model fails to validate on post back because the attendee list that is returned consists of all 0s.Here is the control's code:
<
div
data-container-for
=
"Attendees"
class
=
"k-edit-field"
>
@(Html.Kendo().MultiSelectFor(model => model.Attendees)
.HtmlAttributes(new { data_bind = "value:Attendees" })
.DataTextField("Text")
.DataValueField("Value")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("RemoteDataSource_GetUserList", "Calendar");
})
.ServerFiltering(true);
})
)
</
div
>
6 Answers, 1 is accepted
Adding further to this, the issue appears only when adding new attendees. Removing an attendee works fine. Also, as per instructions here https://docs.telerik.com/aspnet-mvc/html-helpers/editors/multiselect/binding/ajax-binding, my data source is configured as follows:
public JsonResult RemoteDataSource_GetUserList()
{
var allUserList = (from siteusers in context.SiteUsers
select new
{
siteusers.Id,
Name = siteusers.FirstName + " " + siteusers.LastName
}).OrderBy(siteusers => siteusers.Name);
return Json(allUserList, JsonRequestBehavior.AllowGet);
}
Hello,
Would you please elaborate how and at which point do you add or remove the attendees so we could try to replicate the issue at our side and be more helpful with a possible solution?
I will be looking forward to your reply.
Regards,
Plamen
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello and thank you for your response.
As stated, this is a custom editor template used by the Kendo Calendar control. Below is the code that handles create and update functions for the Calendar. The issue is that if an attendee is added either in a brand new meeting or an existing one, the model fails validation. In looking at the returned meeting object, I note that the added attendee as listed in the Attendees array with an ID of 0.
The data read code correctly returns a list of user names and id numbers, and the MultiSelect correctly renders them in HTML. However the id of a selected user does not appear to save in the Attendees array as anything other than 0. Somwhere there is a disconnect.
public virtual JsonResult Resources_Create([DataSourceRequest] DataSourceRequest request, MeetingViewModel meeting)
{
if (ModelState.IsValid)
{
meetingService.Insert(meeting, ModelState);
}
return Json(new[] { meeting }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
public virtual JsonResult Resources_Update([DataSourceRequest] DataSourceRequest request, MeetingViewModel meeting)
{
if (ModelState.IsValid)
{
meetingService.Update(meeting, ModelState);
}
return Json(new[] { meeting }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
Hello,
We have a complete example for a Scheduler with custom editor template in our examples repository. Could you please review it and see if it will help you resolve the problem? If not, kindly provide a small runnable project where I can observe it. I will then debug it and see what is causing the issue.
Regards,
Martin
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.