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

Not able to bind Resources to DataSource

2 Answers 225 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 23 Aug 2013, 12:08 PM
I want to group my scheduler by locations and I'm trying to do so by binding my resources to a datasource. But I can't seem to get it to work (the commented out example - where I use a hardcoded example works fine).

@(Html.Kendo().Scheduler<NFFO_MVC4.Models.BookingViewModel>()
    .Name("Scheduler")
    .Date(DateTime.Today)
    .StartTime(DateTime.Today.AddHours(7))
    .EndTime(DateTime.Today.AddHours(20))
    .Height(600)
    .Width(2000)
    .Messages(message =>
        {
            message.AllDay("Hele dagen");
            message.Today("I dag");
        })
    .Timezone("Europe/Copenhagen")
    .Views(views =>
    {
        views.DayView(day => day.Title("Dag"));
        views.WeekView(week => week.DateHeaderTemplate("<span title='#=kendo.toString(date, 'dddd dd.MMM')#'>#=kendo.toString(date, 'ddd')#</span>").Title("Uge").Selected(true));
        views.MonthView(month => month.Title("MÃ¥ned"));
        views.AgendaView();
    })
        .Group(group => group.Resources("Lokationer"))
        .Resources(resource => resource.Add(m => m.LokationId)
                                    .Title("Lokation")
                                    .Name("Lokationer")
                                    .DataTextField("Navn")
                                    .DataValueField("Id")
                                    .DataSource(ds => ds.Read(read => read.Action("GetLocations", "Scheduler"))))
        //.Resources(resource => resource.Add(m => m.LokationId)
        //                                .Title("Lokation")
        //                                .Name("Lokationer")
        //                                .DataTextField("Text")
        //                                .DataValueField("Value")
        //                                .DataColorField("Color")
        //                                .BindTo(new[] {
        //                            new { Text = "Parken Stadium", Value = 1, Color = "#6eb3fa" },
        //                            new { Text = "Sportspladsen", Value = 2, Color = "#f58a8a" },}))
        .DataSource(d => d
        .Model(m => m.Id(f => f.BookingId))
        .Read("GetBookings", "Scheduler")
    )
)
EDIT: Have both tried with or without 'read => read.Action'

I am pulling the data from the following actions in the SchedulerController:
public ActionResult GetBookings([DataSourceRequest] DataSourceRequest request)
{
    IEnumerable<BookingViewModel> bookingViewModels = _db.Bookinger.Select(booking => new BookingViewModel
        {
            BookingId = booking.Id,
            LokationId = booking.Lokation.Id,
            Title = booking.Aktivitet,
            Description = booking.Aktivitet + " (" + booking.Forening + ")",
            Start = booking.Start,
            End = booking.Slut,
            IsAllDay = false
        });
 
    return Json(bookingViewModels.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
 
public ActionResult GetLocations([DataSourceRequest] DataSourceRequest request)
{
    return Json(_db.Lokationer.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 27 Aug 2013, 05:56 AM
Hello Alexander,

The use of DataSourceRequest is not required when binding the resources DataSource. Therefore, you should remove it from the Action method:

public ActionResult GetLocations()
{
    return Json(_db.Lokationer, JsonRequestBehavior.AllowGet);
}

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alexander
Top achievements
Rank 1
answered on 27 Aug 2013, 07:36 AM
As you already have found out, I'm quite new to the MVC framework and I was not aware of that. Thanks for the help!
Tags
Scheduler
Asked by
Alexander
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or