I`m new to client-server programming concepts. What I need, to send four js vars to my MVC 3 controller action.
$(document).ready(function() {
va
Try changing the name of the object passed to the controller:
$.ajax({
url: '/dashboard/createcover',
type: 'POST',
data: {coordinates : JSON.stringify(myData)}, //change here
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data.success);
},
error: function () {
alert("error");
},
async: false
});
Please note that this will post the values as a JSON object. You need to modify your controller like so:
public ActionResult CreateCover(string jsonCoordinates) {
ImageCoordinates coordinates = JsonConvert.DeserializeObject(jsonCoordinates);
ViewData.Model = coordinates;
return View();
}
You also need to add a reference to Newtonsoft.Json.