小编saf*_*sak的帖子

“无法将多个参数绑定到请求的内容。” 在Web API和angularJs中

当传入多个参数时,WebApi将导致异常"Can't bind multiple parameter to the request's content."。对以下代码有任何解决方案

public class A1
{
   public int id {get;set;}
   public string name {get;set;}
}

public class A2
{
   public int id2 {get;set;}
   public string name2 {get;set;}
}

[Route("Save")]
[HttpPost]
public string Save([FromBody]A1 Emp, [FromBody]List<A2> EmpMarks)
{
}
Run Code Online (Sandbox Code Playgroud)

JS文件

$http({
    method: "post",
    url: "/api/Employee/Save",
    data: JSON.stringify({
        Emp: $scope.Emp,
        EmpMarks: $scope.EmpMarks
    })
}).then(function (response) {

}, function () {
    alert("Error Occur");
})
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net-mvc asp.net-web-api angularjs

6
推荐指数
2
解决办法
8180
查看次数

WebApi“请求的资源不支持http方法'DELETE”

使用 WebApi angularjs 项目并尝试将函数删除为`

     [HttpDelete]
    public String DeleteCountry(string cntryId)
    {
        if (cntryId != null)
        {
            return repoCountry.DeleteCountry(Convert.ToInt32(cntryId));

        }
        else
        {
            return "0";

        }
    }
Run Code Online (Sandbox Code Playgroud)

js函数是

  $http({
            method: "delete",
            url: '/api/Country/DeleteCountry/',
            dataType: "json",
            data: { cntryId: cntryId }
        }).then(function (response) {});
Run Code Online (Sandbox Code Playgroud)

在这里我得到了例外

{"Message":"The requested resource does not support http method 'DELETE'."}
Run Code Online (Sandbox Code Playgroud)

插入、更新和获取功能正常工作。给一个解决方案以及为什么它只发生在删除

c# asp.net-web-api angularjs asp.net-web-api-routing

5
推荐指数
1
解决办法
1万
查看次数