FullCalendarMVC is a HTML helper for FullCalendar. Currently supported version is 3.9.0.
First, install NuGet. Then, install FullCalendar.MVC5 from the package manager console:
PM> Install-Package FullCalendar.MVC5
or FullCalendar.MVC4 if you are using MVC 4:
PM> Install-Package FullCalendar.MVC4
- Reference the script and CSS files in BundleConfig.cs:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/moment.js",
"~/Scripts/fullcalendar*"));
bundles.Add(new StyleBundle("~/bundles/styles").Include(
"~/Content/fullcalendar.css"));
}
or in the view (Shared/_Layout.cshtml for example):
<script src="~/Scripts/jquery-3.2.1.min.js"></script>
<script src="~/Scripts/moment.min.js"></script>
<script src="~/Scripts/fullcalendar.min.js"></script>
<script src="~/Scripts/fullcalendar.helper.min.js"></script>
<link href="~/Content/fullcalendar.min.css" rel="stylesheet" />
- Create an Action in your Controller to get the data:
public JsonResult GetDiaryEvents(DateTime start, DateTime end)
{
return Json(LoadAllAppointmentsInDateRange(start, end).Select(x => new
{
id = x.ID,
title = x.Title,
start = x.StartDateString,
end = x.EndDateString,
color = x.StatusColor,
className = x.ClassName,
someKey = x.SomeImportantKeyID,
allDay = false
}).ToArray(), JsonRequestBehavior.AllowGet);
}
- Use the HTML helper in your view, like below (notice the Events property referencing the Action above):
@Html.FullCalendar(settings =>
{
settings.Name = "calendar";
settings.CssClass = "css-test";
settings.Header = new Header
{
Left = new ControlsBuilder().AddButton(HeaderButton.Prev).AddSeparator(HeaderSeparator.Adjacent)
.AddButton(HeaderButton.Next).AddSeparator(HeaderSeparator.Gap).AddButton(HeaderButton.Today),
Center = new ControlsBuilder().AddTitle(),
Right = new ControlsBuilder("month,agendaWeek ").AddView(AvailableView.AgendaDay)
};
settings.DefaultView = AvailableView.AgendaDay.ToString();
settings.Editable = true;
settings.AllDaySlot = false;
settings.Selectable = true;
settings.SlotDuration = TimeSpan.FromMinutes(15);
settings.Events = Events.AsJsonFeed(Url.Action("GetDiaryEvents", "Home"));
})
- The calendar should be rendered. Check the options below to see if the option you want to use is supported by the HTML helper. For details about these, check the full documentation on the FullCalendar website, or play with some settings in the FullCalendar.UI project of the source code. Also, this CodeProject article might help you understand how the jQuery plugin is linked to ASP.NET MVC.
Have a bug or a feature request? Please search for existing and closed issues before submitting a new one. If your problem or idea is not addressed yet, please open a new issue. Contributions are welcome!
FullCalendarMVC is Copyright © 2017 Hajbok Robert under the MIT license.