I'm new to MVC, and I guess my confusion goes a bit beyond the title of this question, but for starters:
public class TestController : ApiController
{
[HttpPost]
public bool ReceiveHunk(Alterity.Models.Async.HunkDTO hunk)
{
return true;
}
[HttpPost]
public bool A(int x) { return false; }
[HttpPost]
public bool B(int x) { return true; }
}
I can't call my choice of A or B because it seems that the URL only routes to (is that the right term?) the controller, and the method is chosen based on the parameters. Since I have an (int x) on two methods, it doesn't know which to call. My confusion is exacerbated by the fact that when I do:
$.ajax({
cache: false,
type: "POST",
url: ApiLocation + 'Test',
contentType: 'application/json',
dataType: "json",
data: JSON.stringify(5),
success: function (response) { }
});
It still goes to the ReceiveHunk method, with the hunk being null. If I comment out B, ReceiveHunk is still called. Is this related to the fact that I'm using JSON instead of form url encoding? Do I have to have a separate ApiController for every method that has the same signature? Is there some way to configure the routing (or whatsit) to have the URL include the method name? A regular Controller includes the method name in the URL, why doesn't an ApiController? Furthermore, if I change either A or B take zero parameters, I simply get an internal server error (500) without any method being called and no exception. Any info that helps clear this up would be appreciated.