Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Breeze调用POST方法不工作_Breeze_Hottowel - Fatal编程技术网

使用Breeze调用POST方法不工作

使用Breeze调用POST方法不工作,breeze,hottowel,Breeze,Hottowel,我正在使用热毛巾处理单页应用程序。我已经参考了下面使用breeze调用POST方法的链接 var query = breeze.EntityQuery.from('SimilarCustomersPOST') .withParameters({ $method: 'POST', $encoding: 'JSON', $data: { CompanyName: 'Hilo' , Phone: '808-234-5678

我正在使用热毛巾处理单页应用程序。我已经参考了下面使用breeze调用POST方法的链接

var query = breeze.EntityQuery.from('SimilarCustomersPOST')
       .withParameters({
           $method: 'POST',
           $encoding: 'JSON',
           $data: { CompanyName: 'Hilo' , Phone: '808-234-5678' }
       });
下面是我的代码

在服务器端:

  public struct Customer {
            public string CompanyName{ get; set; }
            public string Phone { get; set; }
        } 

    [HttpPost]
    public IQueryable<Customer> SimilarCustomersPOST(Customer customer)
    {
        return repository.CustomersLikeThis(customer);
    }
我得到以下错误: 错误:请求的资源不支持http方法“GET”

当我编写如下服务器代码时:

[System.Web.Http.AcceptVerbs("GET", "POST")]
 [HttpPost]
        public IQueryable<Customer> SimilarCustomersPOST(Customer customer)
        {
            return repository.CustomersLikeThis(customer);
        }
它正在调用但已接受的参数获取空值

请让我知道我得到这个错误的原因是什么


提前感谢。

我不确定当您将[HttpPost]与[AcceptVerbsGET]混合使用时会发生什么,但这可能就是问题所在

请注意,在GET方法中,您需要在非简单值类型的参数前面使用[FromUri]属性,但在POST方法中不需要。很好地解释了WebAPI参数绑定