Can't see appointments on scheduler

Hi,

We have downloaded ASP.Net trials/demos from Telerik, TMS and DevXpress and Scheduler.Net. We think yours looks the best, but we have not been able to get it working, even at a very low level with our (MySQL) data. We can see that you ask for pre-sales support to be via your forums, we ask that you please actively assist us past this blocking stage; we will be happy to purchase once we get this far.

We have followed the patterns of code in your demos. We can debug and see the JSON data being returned in Data(). The ‘active’ lines of code we think important is copied below. We just don’t see anything on the scheduler!

If we cannot get support at this point, please let us know, we will reluctantly have to return to a competitor.

Regards,

Matt Jeffrey

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DHTMLX.Scheduler;
using DHTMLX.Common;
using DHTMLX.Scheduler.Data;
using TeleceteraConnectSvhContext;
namespace SchedulerNetTest
{
public class HomeController : Controller
{
public ActionResult Index()
{
//Being initialized in that way, scheduler will use CalendarController.Data as a the datasource and CalendarController.Save to process changes
var scheduler = new DHXScheduler(this);

        scheduler.Skin = DHXScheduler.Skins.Terrace;
        scheduler.InitialDate = DateTime.Now;
        //scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Month);
        scheduler.Config.multi_day = true;//render multiday events
        scheduler.Data.DataProcessor.UpdateFieldsAfterSave = true;
        scheduler.LoadData = true;
        scheduler.EnableDataprocessor = true;
        return View(scheduler);
    }

    public ContentResult Data()
    {
        TeleceteraConnectSvhDataContext cutData = new TeleceteraConnectSvhDataContext();
        IEnumerable<Job> cutJobs = cutData.Jobs;
        cutJobs = cutJobs.Where(c => c.Assignedto == "awakeham" && c.Scheduleddt != null && c.Scheduleddt > DateTime.Now.AddDays(-1) && c.Scheduleddt < DateTime.Now.AddDays(1));
        var data = new SchedulerAjaxData((cutJobs));
        return Content(data.Render(eventRenderer));
    }

    public void eventRenderer(System.Text.StringBuilder builder, object ev)
    {
        var item = ev as Job;
        DateTime endtime = Convert.ToDateTime(item.Scheduleddt).AddMinutes(Convert.ToInt16(item.Duration));
        builder.Append(
                  string.Format("{{id:{0}, text:\"{1}\", start_date:\"{2:MM/dd/yyyy HH:mm}\", end_date:\"{3:MM/dd/yyyy HH:mm}\"}}",
                  item.Recid,
                  item.Description,
                  item.Scheduleddt,
                  endtime));
    }

public ContentResult Save(int? id, FormCollection actionValues)
{
var action = new DataAction(actionValues);

 var changedEvent = (Job)DHXEventsHelper.Bind(typeof(Job), actionValues);

 TeleceteraConnectSvhDataContext data = new TeleceteraConnectSvhDataContext();

 try
 {
      switch (action.Type)
      {
          case DataActionTypes.Insert: // define here your Insert logic
              data.Jobs.InsertOnSubmit(changedEvent);
                        
              break;
          case DataActionTypes.Delete: // define here your Delete logic
              changedEvent = data.Jobs.SingleOrDefault(ev => ev.Recid == action.SourceId);
              data.Jobs.DeleteOnSubmit(changedEvent);
              break;
          default:// "update" // define here your Update logic
              var eventToUpdate = data.Jobs.SingleOrDefault(ev => ev.Recid == action.SourceId);
              DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "recid" });//update all properties, except for id
              break;
          }
          data.SubmitChanges();
          action.TargetId = changedEvent.Recid;
     }
        catch(Exception e)
        {
            action.Type = DataActionTypes.Error;
        }
        return (ContentResult)new AjaxSaveResponse(action);
    }
}

}

Hi Matt,
there is two common reason why scheduler couldn’t display data. It’s either incorrect format of start/end dates(however, in your code it looks right) or unescaped values of data items that breaks json.

Try one of the following approaches
1)Use the default data renderer.
To do it you just need to select Job items into some intermediate class with all required properties,
e.g.

[code]public ContentResult Data()
{
TeleceteraConnectSvhDataContext cutData = new TeleceteraConnectSvhDataContext();

        var cutJobs = cutData.Jobs.Where(c => c.Assignedto == "awakeham" && c.Scheduleddt != null && c.Scheduleddt > DateTime.Now.AddDays(-1) && c.Scheduleddt < DateTime.Now.AddDays(1))
           .Select(
                c => new { id = c.Recid, text = c.Description, start_date = c.Scheduleddt, end_date = c.Scheduleddt.Value.AddMinutes(c.Duration) }
            );//select Job into anonymous class with all required properties
        var data = new SchedulerAjaxData(cutJobs);
        return data;

}[/code]

2)Or to escape Job.Description values before writing them to JSON. In .Net 4.0 you can use HttpUtility.JavaScriptStringEncode:

public void eventRenderer(System.Text.StringBuilder builder, object ev) { var item = ev as Job; DateTime endtime = Convert.ToDateTime(item.Scheduleddt).AddMinutes(Convert.ToInt16(item.Duration)); builder.Append( string.Format("{{id:{0}, text:\"{1}\", start_date:\"{2:MM/dd/yyyy HH:mm}\", end_date:\"{3:MM/dd/yyyy HH:mm}\"}}", item.Recid, HttpUtility.JavaScriptStringEncode(item.Description), item.Scheduleddt, endtime)); }

Thanks for your help

Hi Aliaksandr,

We use HttpUtility.JavascriptStringEncode to encode values from our DB in the backend, however when they are displayed in the calendar the values remain encoded.

For example, a value from the DB of Some text & an ampersand shows as Some text \u0026 an ampersand in the calendar. This also occurs with other characters such as an apostrophe (\u0027).

How can the data be decoded when loaded to the scheduler?

Hi,

I think HttpUtility is more to do with encoding URL.
If you’re escaping values to prevent unsafe HTML injection (XSS), you could try System.Text.Encodings.Web.HtmlEncoder
It will produce properly escaped html string
Note that you’ll need to install the System.Text.Encodings.Web from NuGet for that.

Here is a sample of usage (that tutorial itself is for .NET Core tutorial, HtmlEncoder works the same way in regular .net)
https://docs.dhtmlx.com/scheduler/howtostart_dotnet_core.html#applicationsecurity

Hi Aliaksandr,

Thanks for the quick response. You are correct and I opted to remove HttpUtility.JavaScriptStringEncode from the entries.

I’m not sure why the encodings were there to begin with, but all seems to be displaying correctly now on the front end calendar including text with special JS characters.

Thanks again!