When using angularJS to call an ASP.Net MVC controller from a service, I encountered an issue with one of the parameters:
$http({
method: "get",
url: "ControllerMethod",
params: {
param1: param1Value,
pageNumber: pageNumber,
pageSize: pageSize,
anythingElse: filter
}
}).success(function (data) {
callback(data);
}).error(function () {
alert("Error.");
});
The controller's method signature is:
public ActionResult GetAssetDepreciationList(
int pageNumber, int pageSize, int param1, MyFilterType filter)
Surprisingly, the "filter" parameter was always arriving as null. This was puzzling as similar methods were working fine.
After changing the parameter name from "filter" to "anythingElse":
anythingElse : filter
the issue got resolved. Could it be possible that "filter" is a reserved word in a specific framework (MVC, Javascript, or angular)?