Click here to Skip to main content
16,016,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a web api controller and a knockout.js page for my js files. i need two post methods in my api controller. Now my code is this:

In knockout.js

self.addTicket = function () {
        $.ajax({
            url: "api/helpdeskapi/Post",
            type: 'post',
            data: ko.toJSON(this),
            contentType: 'application/json',
            success: function (result) { }
        });
        $('#AddNewTicketpopup').dialog('close')



self.addCategory = function () {
            $.ajax({
                url: "api/helpdeskapi/AddCategory",
                type: 'post',
                data: ko.toJSON(this),
                contentType: 'application/json',
                success: function (result) { }
            });



In api controller:


XML
public HttpResponseMessage Post(TKTJOB job)
       {
           HelpDeskRepository.AddJob(job);
           var response = Request.CreateResponse<TKTJOB>(HttpStatusCode.Created, job);
           string uri = Url.Link("DefaultApi", new { id = job.JobId });
           return response;
       }



XML
public HttpResponseMessage AddCategory(JOBCATEGORY category)
        {
            HelpDeskRepository.AddCategory(category);
            var response = Request.CreateResponse<JOBCATEGORY>(HttpStatusCode.Created, category);
            string uri = Url.Link("DefaultApi", new { id = category.CategoryId });
            return response;
        }







when i run this i can post only the ticket values(that is only the first post method is working). Second one is not working.


Can anyone help me in doing this.
Posted

But the above solution does not work.. It always call the first method.

Is there any POC or sample.
 
Share this answer
 
simple way to solve this, just changed the POST menthod name to another name.

Please replace this line
C#
public HttpResponseMessage Post(TKTJOB)
by following line
C#
public HttpResponseMessage JobPost(TKTJOB job)
.

JavaScript
self.addTicket = function () {
        $.ajax({
            url: "api/helpdeskapi/JobPost",
            type: 'post',
            data: ko.toJSON(this),
            contentType: 'application/json',
            success: function (result) { }
        });
        $('#AddNewTicketpopup').dialog('close')
 
Share this answer
 
v2

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