I just started using .net and I'm trying to send data from a .html file to controller using AJAX. My ajax call:
var dataValue = {
ID: 10,
Name: 'Test'
};
$.ajax(
{
url: "/waitingList/apply",
type: "POST",
dataType: 'json',
data: dataValue,
success: function (result) {
console.debug(result);
alert(result);
},
error: function (xhr, status, p3, p4) {
console.debug(xhr);
var err = "Error " + " " + status + " " + p3;
if (xhr.responseText && xhr.responseText[0] == "{")
err = JSON.parse(xhr.responseText).message;
alert(err);
}
});
My controller:
[Route("waitingList/apply")]
public class WaitingListController : Controller
{
[HttpPost]
public string Post(WaitingList wList)
{
return string.Format("Test");
}
}
When I run it, my AJAX return an error: "Not Found". I don't know why. My index.html is in the root and the controller in the controller folder of my MVC project. Does anyone know what I'm doing wrong?
[Route("waitingList/apply")]to the method (not on the controller)url: "/waitingList/post",. And if that is still giving you a 404, post the full details of the error message