I have got this javascript array:
formatData = {
title: title,
start: startFormat,
end: endFormat
};
I would like to send the formatData to a method of the C# controller(and receive it as an array to post to the database):
//HomeController.cs
public ActionResult setReservation()
{
Database db = new Database();
db.setReservations(reservation);
return View();
}
i have tried to send the javascript array with the following AJAX code:
$.ajax({
url: '/Controller/HomeController',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
formatData: formatData
}),
});
with no success. The browser "network" tab shows 404. What am I doing wrong? How can I catch the array from client-side javascript in the server side c# controller as a C# array-like? How could I attach the AJAX post to the setReservation
method in the c#
controller?
Many thanks in advance.
Edit: formatData should pass to the Controller(HomeController.cs). In the controller, the data inside formData(title, start, end) must be passed to a method(setReservations) of an object(db) of another class(Database), where the data will be injected in a sql query string.