This is a migrated thread and some comments may be shown as answers.

Attendee updates not capturing in custom editor template

6 Answers 45 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Responsive
Top achievements
Rank 1
Veteran
Responsive asked on 23 Dec 2020, 10:47 PM

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

Sort by
0
Responsive
Top achievements
Rank 1
Veteran
answered on 24 Dec 2020, 06:10 PM

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);
}
0
Plamen
Telerik team
answered on 25 Dec 2020, 12:06 PM

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/.

0
Responsive
Top achievements
Rank 1
Veteran
answered on 29 Dec 2020, 03:45 PM

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);
}
0
Responsive
Top achievements
Rank 1
Veteran
answered on 29 Dec 2020, 03:52 PM
That last post should be referring to the Scheduler control, not calendar.
0
Martin
Telerik team
answered on 31 Dec 2020, 10:13 AM

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/.

0
Responsive
Top achievements
Rank 1
Veteran
answered on 04 Jan 2021, 08:23 PM
This has been resolved. The issue appears to have been the ValuePrimitive configuration, which I did not have originally. I can find no information on what exactly this does, but including it got things working.
Tags
Scheduler
Asked by
Responsive
Top achievements
Rank 1
Veteran
Answers by
Responsive
Top achievements
Rank 1
Veteran
Plamen
Telerik team
Martin
Telerik team
Share this question
or