2013-07-26 40 views
0

我有波纹简单的API网页API虽然不允许的方法

public class ProductRepository : IProductPrpository 
{ 

    #region IProductPrpository Members 

    public IEnumerable<Product> GetAll(string ProductOption) 
    { 
     return Utility.GetDiscountItems(ProductOption); 
    } 

    public Product GetProduct(string Id) 
    { 
     return Utility.GetProduct(Id); 
    } 
    public String PostBag(Bag bagofItem) 
    { 
     return Utility.PostBagDiscountedItem(bagofItem); 
    } 

    #endregion 
} 

它工作正常,当我打电话GetProduct & GetProduct但当职位邮袋它通过不允许的方法 -

http://localhost:54460/api/products?PostBag=" 

错误 请帮

有我的客户端脚本后数据邮袋阿比

@model List<MultiBuy.Models.Product> 

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Items in the bag</h2> 
    <table> 
    <tr> 
    <th> Item_number_option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </th> 
    <th> Option_number &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </th> 
    <th> Price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>  
    <th> PublicationCode &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>  
    <th> Quantity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </th> 

    </tr> 

    @foreach (var item in Model) 
    { 
     <tr> 
     <td> @item.ItemNumber</td> 
     <td> @item.Option</td> 
     <td> @item.Price</td> 
     <td> @item.PublicationCode</td> 
     <td> @item.Quantity</td> 

     </tr> 
    } 
</table> 
<div> 
<ul id="products" /> 
    <input type="button" value="Search" onclick="find();" /> 
    </div> 
@section scripts { 
<script> 
    function find() { 
    var dataJSON = '@Model'; 

     $.ajax({ 
      type: 'POST', 
      url: 'http://locallhost:54460/api/products?PostBag=', 

      data: JSON.stringify(dataJSON), 
      contentType: 'application/json; charset=utf-8', 
      dataType: 'json' 
     }).done(function (data) { 
      $('#products').text(data) 
     }); 
    }; 

</script> 
} 

感谢所有您的帮助

回答

-1

你不能让一个帖子在你做得到相同的方式,获取你可以把参数在您的网址,但你不容帖子。

http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/

+0

SORRY STILL它不工作我有零钱TO代码以$阿贾克斯({ 类型: 'POST', 网址: 'HTTP://本地主机:54460/API /产品邮袋=' + JSON.stringify(dataJSON)但错误MES NOW http:// localhost:54460/api/products?PostBag =%22System.Collections.Generic.List%601 [MultiBuy.Models.Product]%22“ – rushd

+0

但是你有做这样的: $阿贾克斯({类型: 'POST', 网址: '本地主机:54460/API /产品', 数据:{ “邮袋”:JSON.stringify(dataJSON)} –

+1

有一些并发症但您绝对可以在POST中使用URI参数。 –