I am trying to create a list of resources dynamically from in the controller, but unable to get the schedule control to bind correctly. It just shows an empty form with now schedule control rendered.
I have created a simple MVC5 project with the code shown below. Any help getting this working would be greatly appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Web..Controllers
{
public class TestSchedularController : Controller
{
List<ResourceFields> Owner = new List<ResourceFields>();
List<string> _grpItems = new List<string>();
// To initially bind the appointments with Scheduler
public JsonResult GetData()
{
IEnumerable<Appointment> data = GetList();
_grpItems = data.Select(i => i.ProductCode).Distinct().ToList();
foreach (string item in _grpItems)
{
Owner.Add(new ResourceFields { Text = item, Id = item, Color = "#f8a398", GroupId = "1" });
}
ViewBag.Owner = Owner;
List<String> Group = new List<String>();
Group.Add("Owners");
ViewBag.Group = Group;
return Json(data, JsonRequestBehavior.AllowGet);
}
private List<Appointment> GetList()
{
List<Appointment> appoint = new List<Appointment>();
appoint.Add(
new Appointment
{
AllocationID = 1,
Status = "Allocated",
AllocationStartDttm = new DateTime(2015, 11, 05, 10, 00, 00),
AllocationFinishDttm = new DateTime(2015, 11, 05, 11, 00, 00),
Comment = "Some comments 1",
PickupLocationCode = "WLG",
DropoffLocationCode = "WLG",
ProductCode = "Prod 1"
});
appoint.Add(
new Appointment
{
AllocationID = 2,
Status = "Transfer",
AllocationStartDttm = new DateTime(2015, 11, 05, 11, 00, 00),
AllocationFinishDttm = new DateTime(2015, 11, 05, 11, 25, 00),
Comment = "Some cooments 2",
PickupLocationCode = "WLG",
DropoffLocationCode = "CHC",
ProductCode = "Prod 1"
});
appoint.Add(
new Appointment
{
AllocationID = 3,
Status = "Allocated",
AllocationStartDttm = new DateTime(2015, 11, 05, 10, 00, 00),
AllocationFinishDttm = new DateTime(2015, 11, 05, 11, 00, 00),
Comment = "Some comments 1",
PickupLocationCode = "WLG",
DropoffLocationCode = "PML",
ProductCode = "Prod 3"
});
appoint.Add(
new Appointment
{
AllocationID = 6,
Status = "Allocated",
AllocationStartDttm = new DateTime(2015, 11, 03, 8, 00, 00),
AllocationFinishDttm = new DateTime(2015, 11, 05, 10, 00, 00),
Comment = "Some comments 1",
PickupLocationCode = "WLG",
DropoffLocationCode = "PML",
ProductCode = "Prod 3"
});
appoint.Add(
new Appointment
{
AllocationID = 4,
Status = "Available",
AllocationStartDttm = new DateTime(2015, 10,29, 10, 00, 00),
AllocationFinishDttm = new DateTime(2015, 11, 7, 11, 00, 00),
Comment = "Some comments 1",
PickupLocationCode = "WLG",
DropoffLocationCode = "PML",
ProductCode = "Prod 5"
});
appoint.Add(
new Appointment
{
AllocationID = 5,
Status = "Available",
AllocationStartDttm = new DateTime(2015, 11, 05, 11, 25, 00),
AllocationFinishDttm = new DateTime(2015, 11, 07, 15, 35, 00),
Comment = "Some comments 1",
PickupLocationCode = "WLG",
DropoffLocationCode = "PML",
ProductCode = "Prod 1"
});
return appoint;
}
}
public class Appointment
{
public int AllocationID { get; set; }
public string Subject { get; set; }
public string Status { get; set; }
public string ProductCode { get; set; }
public DateTime AllocationStartDttm { get; set; }
public DateTime AllocationFinishDttm { get; set; }
public string Comment { get; set; }
public string PickupLocationCode { get; set; }
public string DropoffLocationCode { get; set; }
}
public class ResourceFields
{
public string Id { get; set; }
public string Text { get; set; }
public string Color { get; set; }
public string GroupId { get; set; }
}
}