im trying to send some data from my javascript array to my mvc controller.
When i debug through im ending in my method public void GetJSArray(List<SelectorModel> selectorModels)
but selectorModels is null.
Here is my model.
public class SelectorModel
{
public int ID { get; set; }
public string Cords { get; set; }
public string Name { get; set; }
}
here is my C# code in controller.
[HttpPost]
public void GetJSArray(List<SelectorModel> selectorModels)
{
//Code here
}
and here is my JavaScript/Ajax
function SaveInfoSpots() {
var savedeSpots = JSON.stringify({ selectorModels: infospots });
$.ajax({
type: "POST",
url: '/Home/GetJSArray',
contentType: "application/json; charset=utf-8",
dataType: 'JSON',//json
data: savedeSpots,
traditional: true
});
}
If i make a console.log(savedeSpots) i get this.
{"selectorModels":[{"ID":1,"Name":"Infospot1","Cords":"5000.00, 2293.85, 2278.05"},{"ID":1,"Name":"Infospot2","Cords":"1.94, 584.50, 5000.00"},{"ID":1,"Name":"Infospot3","Cords":"5000.00, -2705.97, -277.02"},{"ID":1,"Name":"Infospot4","Cords":"5000.00, 504.93, -2845.93"}]}
[FromBody]to the param in the controller?