Hi, I'm trying to pass an array of objects from my javascript in my view to my controller.
After some issues I managed to get it to work, at least until the point that my method in the controller get called and my list<> there get correctly filled.
but at the same time my page is not showing and I get HTTP Error 415.
I have read that I need to use [FromFrom] instead of [fromBody]
but then the result of my canvasFields is empty (list Count = 0)
But with [FromBody] when I set a breakpoint in my controller canvasFields is correctly filled only that my page is not showing with Http Error 415
I really have no idea what to do
What I have tried:
$('#btnClick').click(function (e) {
$.ajax({
url: "@Url.Action("SaveTemplate")",
type: 'post',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(canvasFields),
success: function () {
alert("yes");
},
error: function (errMsg) {
alert(errMsg);
}
})
});
[HttpPost]
public ActionResult SaveTemplate([FromBody] List<CanvasField> canvasFields)
{
return Json(new
{
resut = "OK"
});
}