Struggling with sending a JavaScript value from my razor page to a controller in ASP.NET. The value always ends up being null, despite reaching the controller breakpoint. I've searched for solutions without much success.
I'm not very familiar with JavaScript, so any tips or guidance would be greatly appreciated. Here's the snippet of JavaScript causing the issue:
var clickButton = function (buttonId) {
$.ajax({
type: "POST",
async: false,
cache: false,
crossDomain: false,
contentType: "application/json; charset=utf-8",
url: "v1/buttons",
dataType: "json",
data: '{ buttonId:'+JSON.stringify( "buttonId" ) + '}',
success: function (result) {
//console.log("clickButton OK => " + result);
},
timeout: 500
});
}
Here is the corresponding C# controller code:
[Route( "v1/[controller]" )]
public class ButtonsController : Controller
{
...
[HttpPost]
public IActionResult OnButtonClicked( string buttonId )
{
// buttonId = null !!!
...
Additionally, encountering issues passing a boolean value to another controller where it defaults to false. Could this be related to a security restriction preventing unauthorized users from sending data via POST?