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

BindTo After Read Action

3 Answers 131 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Shimon
Top achievements
Rank 2
Shimon asked on 10 Apr 2014, 01:56 PM
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" ?

3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 14 Apr 2014, 02:11 PM
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.

 
0
Shimon
Top achievements
Rank 2
answered on 17 Apr 2014, 08:23 AM
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.
0
Alexander Popov
Telerik team
answered on 21 Apr 2014, 07:33 AM
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.

 
Tags
Scheduler
Asked by
Shimon
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Shimon
Top achievements
Rank 2
Alexander Popov
Telerik team
Share this question
or