Error with binding remoted resources

5 posts, 1 answers
  1. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 09 Sep 2013 Link to this post

    Hello,

    I have some troubles about resources in scheduler, so I come here to find some help.
    I want to make a scheduler for some employees. For a better readability, I would like that every user's event has a unique color. Colors are stored in database, on with all User's data. So I decided to use Resources to do this.

    However, when I define a remote loading for resources, then scheduler raise on error (see below) and stop working.
    Here is Razor code :

    @(Html.Kendo().Scheduler<EventViewModel>()
              .Name("calendar")
              .Date(DateTime.Now)
              .Timezone("Etc/UTC")
              .Views(v =>
              {
                  v.DayView();
                  v.WeekView(conf => conf.Selected(true));
                  v.MonthView();
                  v.AgendaView();
              })
              .DataSource(source => source
                  .Model(conf =>conf.Id(f => f.EventId))
                  .AutoSync(true)
                  .Read("GetAllEvents", "Activity")
                  .Create("CreateEvent", "Activity")
                  .Destroy("DestroyEvent", "Activity")
                  .Update("UpdateEvent", "Activity")
              )
            .Resources(resources => resources.Add(m => m.Creator)
                .Title("User")
                .DataTextField("Name")
                .DataValueField("UserId")
                .DataColorField("Color")
                .DataSource(source => source
                    .Read(read => read.Action("GetUsersList", "Activity"))))
    )

    If I remove .Resources() part, all is working great. Defining some static resources (with .BindTo(new[]{...})) works well too, but this way is not handy.
    Finally, when I want to define a resources section with remote loading, I got the following error messages in FireFox :

    TypeError: t is undefined @ /Scripts/kendo/2013.2.716/kendo.all.min.js:31
    TypeError: n.slice is not a function @ /Scripts/kendo/2013.2.716/kendo.all.min.js:11


    Users list is perfeclty loaded in my page. Here is GetUsersList() code :
    public ActionResult GetUsersList([DataSourceRequest] DataSourceRequest request)
    {
        var items = from x in db.Users
                            select new {x.UserId, Name = x.FirstName + " " + x.LastName, x.Color};
        return Json(items.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

    One thing I notice is that, when resources are loaded up, scheduler does not trigger any loading for events. I'm not yet used to scheduler helper, so it's not really easy to understand what issue is.

    Thanks you for your help.

    Best Regards,
    Claude
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 10 Sep 2013 Link to this post

    Hello Claude,

    I suspect that the issue is caused by the use of DataSourceResult in the action method serving the resources data. As you may know this is not required and should be omitted:

    public ActionResult GetUsersList()
    {
        var items = from x in db.Users
                            select new {x.UserId, Name = x.FirstName + " " + x.LastName, x.Color};
     
        return Json(items, 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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 10 Sep 2013 Link to this post

    Hello Rosen and thanks you for your answer.

    So, I tried your solution and removed DataRequest stuff. I did not modify anything else.
    Now, scheduler does not crash anymore, but resources still not working. I can see that resources and events are well loaded, but binding fail with the following error :

    TypeError: t is undefined @ /Scripts/kendo/2013.2.716/kendo.all.min.js:31

    Is there some options I forgot  ?

    Regards,
    Claude
  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 11 Sep 2013 Link to this post

    Hi Claude,

    Unfortunately, I'm not sure what may be the cause for the described error looking at the details provided. Thus, please send us a small runnable sample in which it can be observed locally.

    Regards,
    Rosen
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Answer
    Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 17 Sep 2013 Link to this post

    Hi Rosen,

    I finally found the bug. The issue come from model declaration in Resources part :
    .Resources(resources => resources.Add(m => m.Creator.UserId)
    Error comes from "Creator.UserId" which Sheculer does not like. So I modified my view model to integrate this information to avois this situation :
    .Resources(resources => resources.Add(m => m.CreatorId)
    Now it works. Please ote that "t is undefined" error still raising,

    Thanks you for your help.

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