Why I cant send data to my action method and allway isNull is returned back ?
Cant send data to my controller using ajax
function LoadUpsert() {
var request = { name: "John", age: 31, city: "New York" };
var myJSON = JSON.stringify(request);
$.ajax({
type: "post",
cache: false,
url: "/Admin/Category/Upsert",
data: "myJSON",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result);
},
error: function (result) {
alert("No Connection to server");
},
});
}
this is my action method :
[Area("Admin")]
public class CategoryController : Controller
{ [HttpPost]
public IActionResult Upsert([FromBody] string myJSON)
{
string myMessage = (myJSON != null) ? "Not Null" : "isNull";
return Json(myMessage);
}
when i press the related button allways says isNull, in fact myJSON in my controller is allways null.