I have a json string (json representation of a javascript array), which I want to pass to a C# controller method. However, I am either seeing the c# method parameter as null or the breakpoint not being hit.
Here is the js code:
$.ajax({
url: "/Home/PersistSelections",
type: 'post',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: { "json": JSON.stringify(selectedItems) }
})
Where "seleteditems" is just a javascript colleciton.
My c# code is:
[HttpPost]
public void PersistSelections([FromBody] string json)
{
}
However, this is likely not the right way of doing this? I am always seeing the json parameter is null.
Any tips appreciated!