I am trying to get to the Web API get controller using $http. Get in angular application as follows:
$http.get(BasePath + ‘/api/documentapi/GetDocuments/‘ ,
{ params: {
PrimaryID: ID1,
AlternateID: ID2,
}
}).then( ...
In my case, either the Primaryid or the Alternateid would have the value. So, one of them'll is null always.
My Web API method is
Public Documentsdto[] GetDocuments (decimaldecimal? ) Alternateid) {...
When one of the value was null, the URL generated by $http. Get is as follows:
http://BaseServerPath/api/documentapi/GetDocuments/?PrimaryID=1688
Or
http://BaseServerPath/api/documentapi/GetDocuments/?SecondaryID=154
This does isn't hit my Web API method.
However if I use
http://BaseServerPath/api/documentapi/GetDocuments/?PrimaryID=1688&SecondaryID=null
It can works. I can hardcode the values to null in my params, however I would like to know if there are any correct the-to-achieve this.
Although I specified on my WEB API controller that the both parameters can be null, the ASP. Routing engine would still B e looking for the parameters in a, and even if one of them is null.
Although I can specify which parameter corresponds to the supplied value in the query string, both these methods would have The same signature (a single parameter of typedecimal) in my controller class.
The solution is to has the default values for the Web API parameters.
So, I has one method which takes an object containing one ID set to a value and the other to null, and run my query based On that. as follows:
Public Documentsdto[] GetDocuments (decimalnulldecimalnull) {...
Angularjs: $http. Get with null parameters is not hitting the WEB API controller