I have the following controller method:
[HttpPost]
public IActionResult AddNewMessage(string recipientUserId, string message)
{
var currentLoggedInUserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
_chatMessageRepository.AddNewMessage(currentLoggedInUserId, recipientUserId, message);
return Ok();
}
And I am trying to send data to it, using the following JQuery code:
var data = {
recipientUserId: selectedUser,
message: message
};
$.ajax({
url: '/api/chatmessages',
type: 'POST',
data: data,
success: function (data) {
alert(data.success);
},
error: function () {
alert("error");
}
});
The result of this code, is that I get the request on my controller, but the parameters are always NULL no matter what. Additionally, I tried to call the function JSON.Stringify() upon the data, before sending them, but it did not do any difference. Keep in mind that I am devilishly trying to avoid to use a model class in this scenario, for project related reasons.