2014-01-16 37 views
0

我正在使用HotTowel处理单页应用程序。我在下面提到了使用breeze调用POST方法的链接。使用Breeze调用POST方法不起作用

http://www.breezejs.com/breeze-labs/breezeajaxpostjs

下面是我的代码。

在服务器端:

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

    [HttpPost] 
    public IQueryable<Customer> SimilarCustomersPOST(Customer customer) 
    { 
     return repository.CustomersLikeThis(customer); 
    } 

使用微风调用POST方法。

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

我得到以下错误: 错误:请求的资源不支持HTTP方法“GET”。

当我写类似下面的服务器代码:

[System.Web.Http.AcceptVerbs("GET", "POST")] 
[HttpPost] 
     public IQueryable<Customer> SimilarCustomersPOST(Customer customer) 
     { 
      return repository.CustomersLikeThis(customer); 
     } 

正在调用,但接受的参数越来越空值。

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

在此先感谢。

回答

0

我不确定当您将[HttpPost][AcceptVerbs("GET")]混合时会发生什么情况,但这可能是问题所在。

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