I am trying to post array of a simple object to my MVC core controller with the Frombody attribute, but for some reason it coming as null. If I post just a single object it is working fine here is my code:
$(document).ready(function() {
var tk = new Array();
$("#calendar").fullCalendar({
header: {
left: 'prevYear,prev,next,nextYear',
center: 'title',
right: 'month,agendaWeek,agendaDay',
},
defaultView: 'month',
editable: true,
alldayslot: false,
selectable: true,
slotminutes: 15,
nextDayThreshold: "00:00:00",
events: "/Home/FullCalendar",
eventDrop: function(event, delta, revertFunc)
{
Update(event);
},
});
function Update(event) {
var datarow =
{
"id": event.id,
"start": event.start,
"end": event.end,
}
tk.push(datarow);
debugger;
confirm(("Save changes?"))
console.log(JSON.stringify(datarow));
$.ajax({
type: "post",
dataType: 'json',
cache: false,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(tk),
url: '@Url.Action("JSON", "Home")',
success: function (data) {
debugger;
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
debugger;
}
});
}
});
My Controller class
[HttpPost]
public IActionResult UpdateTask([FromBody] List<Task_fullcal> td)
{
// Do something
// td is always null if passed as an array
//td working fine if passed as single value
}
data: JSON.stringify({ tk: tk }),Task_fullcalcontain propertiesint id,DateTime startandDateTime end? (and that was supposed to be{ td: tk }(not{ tk: tk }))