Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there
i have got the bellow simple api
C#
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
    }


it is working fine when i call GetProduct & GetProduct but when post for PostBag it through the above error
please help

there is my client side script which post data to PostBag Api

C#
@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://localhost:54460/api/products?PostBag=',
                data: JSON.stringify(dataJSON),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json'
            }).done(function (data) {
                $('#products').text(data)
            });
        };

    </script>
}

appreciate all your help
Posted

1 solution

Add one more route on the top in wbApiConfig like below
C#
config.Routes.MapHttpRoute(
               name: "ApiByAction",
               routeTemplate: "api/{controller}/{action}",
               defaults: new { action = "Post" }
           );


C#
/api/Product/PostBag

Hope this helps
 
Share this answer
 
v3
Comments
rushdy20 26-Jul-13 7:04am    
by making the above change i did do any differnt. still the error is same.
Jameel VM 26-Jul-13 7:21am    
i have updated my answer.please try that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900