I want pass values from my view to a controller action however every time i do the parameter is null. I've seen multiple posts about the same things but can't quite seem to get it right.. my code is below
Controller Action
[HttpPost]
public IActionResult GetTest(string data)
{
var jSon = JsonConvert.SerializeObject(channles[0]);
return Json(jSon);
}
View (AJAX) code
function testAjax() {
$("#searchButton1").click(function () {
$.ajax({
type: "POST",
url: '@Url.Action("GetTest", "DataGridWebApi")',
data: { data: "test" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("Hello: " + response.Name + " .\nCurrent Date and Time: " + response.DateTime);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
}
I hit the breakpoint in my controller action but the parameter is always null. I've also tried changing my controller action to accept an object instead of a string but nothing seems to work.
What am i doing wrong?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)