I am trying to pass the fullcalendar events to my controller via Json, however I am getting null passed through to my controller?
what am I doing wrong?
Here is my view code:
<script type='text/javascript'>
$(document).ready(function () {
$(function () {
$("#save").click(function () {
var eventsFromCalendar = $('#calendar').fullCalendar('clientEvents');
alert(eventsFromCalendar);
$.ajax(
{
url: '@Url.Action("Save")',
type: 'POST',
traditional: true,
data: eventsFromCalendar,
dataType: "json",
success: function (response) {
alert(response);
},
error: function (xhr) {
debugger;
alert(xhr);
}
});
});
});
});
</script>
And my controller:
[HttpPost]
public JsonResult Save(object[] data)
{
// edit the item and get it back
return Json("success");
}
When I break into the Jscript and look at eventsFromCalendar it is populated fine.
Try converting your events to JSON text:
(see JSON.stringify Function (JavaScript))
Then use a tool like Json.NET to parse the posted JSON string in your controller action: