angularjs - When send individual parameter, action result cannot be hit. when send object, it gets hit -
i have 1 application consist of asp.net webapi 2 , web project angularjs used. problem when call api parameters, not hit. , when send object, gets hit.
anjularjs code:
with parameters
$http({ cache: false , method: 'post' , url: 'http://localhost:51341/api/user/updateuser' , data: { userid: $scope.usersid, fullname: $scope.name } }).success(function (data, status, headers, config) { }) .error(function (data, status, headers, config) { });
webapi code
[httppost] public apiresponse updateuser(int userid, string fullname) { return this.response(true, messagetypes.success, "user has been saved successfully."); }
with object
var model = { userid: $scope.usersid, fullname: $scope.name }; $http({ cache: false , method: 'post' , url: 'http://localhost:51341/api/user/updateuser' , data: model }).success(function (data, status, headers, config) { }) .error(function (data, status, headers, config) { });
webapi code
[httppost] public apiresponse updateuser(user model) { return this.response(true, messagetypes.success, "user has been saved successfully."); }
user class
public class user { public int userid { get; set; } public string fullname { get; set; } public int age { get; set; } public string address1 { get; set; } public string address2 { get; set; } }
when call made parameters, api not hit. when call made object, api gets hit.
what missed when call made parameters ? appreciated.
from webapi docs:
at 1 parameter allowed read message body. not work:
// caution: not work! public httpresponsemessage post([frombody] int id, [frombody] string name) { ... }
for other info suggest read:
https://damienbod.wordpress.com/2014/08/22/web-api-2-exploring-parameter-binding/ https://stackoverflow.com/a/24629106/3316654
Comments
Post a Comment