Normally in a normal website/WebApp I would write:
[WebMethod]
public void CommitChange
Then I could call this method from Ajax
$.ajax({
url: "Dummy.aspx/CommitChange"
Now I want to call a method from Ajax code and I am using MVC, so the Url convention is different. And I see that the [WebMethod] annotation is no longer supported. I have the following Ajax:
$.ajax({
url: '@Url.Action("~/Controller/UploadImage")',
type: "POST",
data: {},
dataType: "xml",
success: function () {
alert("Success");
},
error: function () {
alert("Error");
}
});
And the method I want to call:
[HttpPost]
public ActionResult UploadImage(HttpPostedFileBase fileUpload)
{... }
I am not reaching the method. The problem is surely here:
url: '@Url.Action("~/Controller/UploadImage")'
How can I call the method?