BindTo After Read Action

4 posts, 0 answers
  1. Shimon
    Shimon avatar
    18 posts
    Member since:
    Jul 2013

    Posted 10 Apr 2014 Link to this post

    Hello.
    I have a scheduler and an EditorTemplate.
    I want to bind a multiselectfor after the reading method. (with my Model which is populated in the read Method).
    I suppose the .BindTo() Display nothing because the read method 'll be call after this one.

    So here is my scheduler :

    @(Html.Kendo().Scheduler<iMail.Web.Models.TaskViewModel>()
                .Name("scheduler")
                .Date(DateTime.Now)
                .Timezone("Etc/UTC")
                .Views(views =>
                {
                    views.DayView();
                    views.WeekView();
                    views.MonthView();
                    views.AgendaView(agenda => agenda.Selected(true));
                })
                .Selectable(true)
                .Timezone("Etc/UTC")
                .Events(e =>
                {
                    e.Edit("onEdit");
                    e.Change("onChange");
                })
                .Editable(editable =>
                {
                    editable.TemplateName("_EditorTemplatePartial");
                })
                .DataSource(d => d
                        .Model(m =>
                        {
                            m.Id(f => f.TaskID);
                            m.Field(f => f.Title).DefaultValue("No title");
                            m.RecurrenceId(f => f.RecurrenceID);
                            m.Field(f => f.Priority);
                            m.Field(f => f.TypeID);
                        })
                    .Events(e => e.Error("error_handler"))
                    .Read (read => read.Action("TasksRead", "Calendar").Data("additionalInfo").Type(HttpVerbs.Get))
                    .Create(create => create.Action("TasksCreate", "Calendar").Data("additionalInfo"))
                    .Destroy(destroy => destroy.Action("TasksDestroy", "Calendar").Data("additionalInfo"))
                    .Update(update => update.Action("TasksUpdate", "Calendar").Data("additionalInfo"))
                )
            )



    And here is my MultiSelectFor in the _EditorTemplatePartial.cs file.
    <div id="AttendeeAlreadyInvited">
        <div data-container-for="AlreadyInvitedID" class="k-edit-field">
            @(Html.Kendo().MultiSelectFor(model => model.AlreadyInvitedID)
                .HtmlAttributes(new { data_bind = "value:AlreadyInvitedID" })
                .DataTextField("Name")
                .DataValueField("ID")
                .BindTo(Model.Invited) 
            )
        </div>
    </div>

    Model.Invited has a structure like this :

    public class CalEmployeeLight
    {
      public int ID;
      public string Name;
     }

    Here is a part of my model :

    public class TaskViewModel : Kendo.Mvc.UI.ISchedulerEvent
    {
       public int TaskID { get; set; } //each event have an ID.
       .....
       public IEnumerable<
    int> AlreadyInvitedID { get; set; }
       public ICollection<CalEmployeeLight> Invited { get; set; }
    }

    Each event in the Scheduler have an ID (TaskID)

    The Model is populated in the TaskRead fct and works correctly.
    But my multiselectFor is empty.

    How can i use .bindTo() fct in the MultiSelectFor() after the Model is populated by "TaskRead" ?

  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 14 Apr 2014 Link to this post

    Hi Shimon,

    I tried to reproduce the problem locally but to no avail – everything is working as expected on our side (most probably the ViewModel is not populated correctly). Could you please provide runable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.


    Kind Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Shimon
    Shimon avatar
    18 posts
    Member since:
    Jul 2013

    Posted 17 Apr 2014 in reply to Vladimir Iliev Link to this post

    Here is a runable sample : http://www.filehosting.org/file/details/446030/7dcb826e-9aae-631b-85d4-ff000054ddc5_schedulercustomeditor_mvc.zip

    The size of the file was too heavy to attach on the board.

    I populated the data in the function public virtual IQueryable<MeetingViewModel> GetAll()
    (cf the file SchedulerMeetingService)

    Thanks a lot.
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 21 Apr 2014 Link to this post

    Hello Shimon,

    Binding a widget's source to a Model inside a template is not supported, because the Model is used only for its metadata and it is empty at the time the template is being executed. In case you wish to avoid remote binding, I would suggest using the ViewData to pass the attendees list. For example: 
            public ActionResult Index()
            {
                ViewBag.Message = "Welcome to ASP.NET MVC!";
                ViewData["attendeesList"] = new List<CalEmployeeLight>()
                {
                    new CalEmployeeLight{ Name = "Alex", ID = 1, },
                    new CalEmployeeLight{ Name = "Bob", ID = 2,   },
                    new CalEmployeeLight{ Name = "Charlie", ID = 3 }
                };
                return View(new MeetingViewModel());
    ...
     
        <div data-container-for="AlreadyInvitedID" class="k-edit-field">
            @(Html.Kendo().MultiSelectFor(model => model.AlreadyInvitedID)
                .DataTextField("Name")
                .DataValueField("ID")
                .BindTo((List<SchedulerCustomEditor.Models.CalEmployeeLight>)ViewData["attendeesList"])
            )
        </div>


    Regards,
    Alexander Popov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready