I am new to ajax, am trying to send username value to Answer function then return it back to the view , but i get undefined no matter what i tried.
//Answer function from the HomeController.cs
[HttpPost]
public string Answer(string userName)
{
return userName;
}
//ajax call from the view
$.ajax({
type: "POST",
url: "/Home/Answer",
contentType: "application/json; charset=utf-8",
data: '{"userName":"' + message + '"}',
dataType: "html",
success: function (result, status, xhr) {
alert(message);
outputArea.append(`
<div class='user-message'>
<div class='message'>
${result}
</div>
</div>
`);
},
error: function (xhr, status, error) {
alert("Something went wrong");
}
});