On the HTML:
<div>
<button onclick="clicker()">Click Me!</button>
</div>
<script type="text/javascript">
function clicker() {
var data = {
id: 1,
name: 'julius'
};
$.ajax({
type: 'POST',
url: '/api/test/',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8"
});
}
</script>
On the Controller:
public class TestController : ApiController
{
public void Post([FromBody]string value)
{
Console.WriteLine();
}
}
The value of the variable "value" on the controller is null, although, I pass data to ajax call. Can somebody please explain why this happens?