Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i need samples and examples for post,delete,put method on MVC web API with Knockout js. i got an error while running Post method in MVC web API. pls give solution ASAP.

here my code for Post Method:

$.ajax({
                       url: 'api/product/PostProduct/',
                       cache: false,
                       type: 'POST',
                       contentType: 'application/json; charset=utf-8',
                       data: ko.toJSON(Product),
                       success: function (data) {
                            alert('added');
                           self.Products.push(data);
                           self.BrandName("");
                           self.price("");
                           self.GenericName("");
                       }
                   }).fail(
                        function (xhr, textStatus, err) {
                            alert('error');
                        });
Posted

1 solution

JavaScript
url: 'api/product/PostProduct/',

This line identifies an address and not a method (notice the ending / character!!!)
You should write it like this (where PostProduct is the name of your method on the server side)
JavaScript
url: 'api/product/PostProduct',
 
Share this answer
 

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