my problem comes when call webapi2 get string parameter has special char (with normal character works correctly).
angularjs
this.getbycontactvalue = function (contactvalue) { return $http.get("/api/subjects/"+ contactvalue+ "/contactvalue" ); }
c#
[route("api/subjects/{contactvalue}/contactvalue")] public ienumerable<subject> getbycontactvalue(string contactvalue) { return repository.getbycontactvalue(contactvalue); }
the response 404 error. tried modify request in way
this.getbycontactvalue = function (contactvalue) { var request = $http({ method: "get", url: "/api/subjects/contactvalue", //modified route in c# controller data: contactvalue }); return request; }
but error same.
which best way call webapi?
you've pass data in query strings as
$http({ url: "/api/subjects/contactvalue", method: "get", params: {contactvalue: contactvalue} });
update action
[route("api/subjects/contactvalue?contactvalue={contactvalue}")] public ienumerable<subject> getbycontactvalue(string contactvalue) { return repository.getbycontactvalue(contactvalue); }
Comments
Post a Comment