Reputation: 290
I'm implementing FullCalendar
in a project, I've inserted some Events into the database and returned them to Json
. But by displaying them on the screen, they come with the correct date time, but the display does not show in the correct place.
Example, the data comes with the bank start date of the event at 06:00, but are displayed at 10:00 in the morning.
In the image below, the event has start times at 06:30, and ends at 07:00.
But it shows on the screen that the time is at 10:30
My Evento
Model:
public class Eventos
{
[Key]
public int ID { get; set; }
public string title { get; set; }
public DateTime start { get; set; }
public DateTime? end { get; set; }
public int StatusEnum { get; set; }
}
My Controller
:
public JsonResult ObterEventos(string start, string end)
{
var db = new AgendaOnlineFc();
var dtInicial = Convert.ToDateTime(start).Date;
var dtfinal = Convert.ToDateTime(end).Date;
var lista = db.Eventos
.Where(d => d.end < dtfinal && d.start > dtInicial)
.ToList();
return Json(lista, JsonRequestBehavior.AllowGet);
}
My Script
:
$('#calendar').fullCalendar({
events: '/Home/ObterEventos/'
});
And my Return Json
{ID: 10, title: "teste", start: "/Date(1495449000000)/"
, end: "/Date(1495450800000)/", StatusEnum: 0}
ID:10 StatusEnum:0 end:"/Date(1495450800000)/" start:"/Date(1495449000000)/" title:"teste"
Is there any additional configuration to be made? Or if not where am I going wrong in this implementation?
Upvotes: 1
Views: 2416
Reputation: 96
public DateTime start { get; set; }
public DateTime? end { get; set; }
use String instead and format it in following:
rec.start = model.AllReservationsFromSchedule[i].start.ToString("s");
model.AllReservationsFromSchedule[i].start is DateTime variable.
ToString("s") will generate string format YYYY-MM-DDTHH:MM:SS
After that your JSON will return correct date format for FullCalendar.
Upvotes: 2