如何使用angularjs调用带有两个参数的web api Controller方法

Has*_*tar 0 asp.net-mvc-4 asp.net-web-api angularjs

我是angularjs中的新手,我环顾四周试图在此找到一些帖子,但有很多但没有解决我的具体问题(我能找到).

就这么简单,我想通过angularjs($ http POST)发送两个参数,其中我的第一个参数是类对象的json,第二个是int.我尝试了什么:

        var url = '../Request/'+ id;
        $http({
            method: 'POST',
            url: url,
            data: Data
        }).success(function (data, status, headers, config) {
            deferred.resolve(data);
        }).error(function (data, status, headers, config) {
            debug.error(data);
            deferred.reject('An error occured while saving the request');
        });
Run Code Online (Sandbox Code Playgroud)

在我的web api控制器中,我有:

    [POST("Request/{id}")]
    public bool SaveRequest(Data data, int id)
    {
       ...
       ...   
    }
Run Code Online (Sandbox Code Playgroud)

当我只发送数据时,它适用于我,但当我尝试添加Id和数据时,它都无法正常工作.请让我知道需要做些什么,谢谢.

ssi*_*777 5

你尝试过使用这样的[FromBody]属性 吗?

 [POST("Request/{id}")]
 public bool SaveRequest([FromBody] Data data,[FromUrl] int id)
 {
      ...
Run Code Online (Sandbox Code Playgroud)

有关参数绑定的更多信息