I have an MVC
application with aspx
file as the view. In the codebehind I have this function
[WebMethod]
public static string GetProduct1()
{
return "Hi!";
}
In the aspx
file I use ajax to call the method
$.ajax({
type: "POST",
url: "selection.aspx/GetProduct1",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Do something interesting with msg.d here.
console.log(msg);
},
error: function (response) {
console.log(response);
}
});
The error I got is 404
. I am not sure why. I have tried adding a new reference for system.web.extensions
and download ajax
extension. I have tried adding ignoreroute in the routeconfig. But nothing seems to be working. This is the controller.
public ActionResult selection()
{
ViewBag.Title = "Home Page";
return View();
}
Is the problem in the controller or maybe I am not supposed to use aspx for this?