2015-09-21 28 views
0

我有一個應用程序組成的ASP.Net WebAPI 2和Web項目使用angularJS。問題是當我用參數調用API時,它沒有命中。當發送對象時,它會被擊中。發送個別參數時,無法點擊動作結果。當發送對象,它被擊中

anjularJS代碼:

與參數

$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代碼

[HttpPost] 
public ApiResponse UpdateUser(int userId, string fullName) 
{ 
    return this.Response(true, MessageTypes.Success, "User has been saved successfully."); 
} 

與對象

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代碼

[HttpPost] 
public ApiResponse UpdateUser(User model) 
{ 
    return this.Response(true, MessageTypes.Success, "User has been saved successfully."); 
} 

User類

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; } 
} 

當參數進行調用,API不被打到。但是當使用Object進行調用時,api GETS命中。

我在參數調用時錯過了什麼?幫助將得到真正的讚賞。

回答