Dynamic MultiSelect in Scheduler edit Template

2 posts, 0 answers
  1. Tyler
    Tyler avatar
    46 posts
    Member since:
    Nov 2013

    Posted 22 Mar Link to this post

    Ive a scheduler with a custom editor template. The template displays a MultiSelect whose selectable values will differ depending upon what specific event is picked. So when I click an event I capture the Edit event and I refresh the MultiSelect to populate its selecteble values and this works.

     

    $('#PrerequisiteOids').data('kendoMultiSelect').dataSource.read();

     

    However my selected values from my model are never set in the control. I'm guessing this is something to do with it being in a Template - how do I bind my values from the selected Event?

    The MultiSelect in the Template looks like this:

    @(Html.Kendo().MultiSelectFor(model => model.Prerequisites)
      .Name("Prerequisites")
      .AutoBind(true)
      .DataTextField("Title")
      .DataValueField("Oid")
      .DataSource(source =>
      {
        source.Read(read =>
        {
        read.Action("GetPrerequisites", "CourseCalendar").Data("getCourseEventID");
        })
      .ServerFiltering(true);
      })
      .HtmlAttributes(new { @class = "universalWidth" }))

     

    Has 

     

     

     

  2. Tyler
    Tyler avatar
    46 posts
    Member since:
    Nov 2013

    Posted 23 Mar in reply to Tyler Link to this post

    This problem has been solved. The issue related to how the data was being bound to the MultiSelectFor component. In the Html.Kendo().Scheduler .Edit() event I was setting the Guid of the selected calendar item in a hidden field then calling the dataSource.read() for the MultiSelectFor component manually.

    This triggered the read.Action which called the getCourseEventID JavaScript function to return the Guid from the hidden field. As the .Edit() event is raised after the MultiSelectFor is initialised, the selected values from my model were never being set in the control.

    I got around this by passing in the CourseEventId directly as part of the DataSource read action which is binding automatically. I’m no longer using Edit() event.

     

    @(Html.Kendo().MultiSelect()
      .Name("Prerequisites")
      .Value(Model.Prerequisites)
      .DataTextField("Title")
      .DataValueField("Oid")
      .DataSource(source =>
      {
        source.Read(read =>
        {
          read.Action("GetPrerequisites", "CourseCalendar", new { @courseEventOid = "#: CourseEventOid #" });
        })
      .ServerFiltering(true);
      })
      .HtmlAttributes(new { @class = "universalWidth" }))
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top