我有下面的简单 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 时它工作正常,但是当通过不允许的方法发布 PostBag 时 -
http://localhost:54460/api/products?PostBag="
错误请帮忙
有我的客户端脚本将数据发布到 PostBag Api
@model List<MultiBuy.Models.Product>
@{
ViewBag.Title = "Index";
}
<h2>Items in the bag</h2>
<table>
<tr>
<th> Item_number_option </th>
<th> Option_number </th>
<th> Price </th>
<th> PublicationCode </th>
<th> Quantity </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>
}
感谢您的所有帮助