且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

web api控制器中的多个帖子

更新时间:2023-02-12 16:15:29

.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,
类型:'post',
数据:ko.toJSON(this),
contentType:'application / json',
成功:函数(结果){}
});







在api控制器中:





 public HttpResponseMessage P ost(TKTJOB job)
{
HelpDeskRepository.AddJob(job);
var response = Request.CreateResponse < TKTJOB > (HttpStatusCode.Created,job);
string uri = Url.Link(DefaultApi,new {id = job.JobId});
返回回复;
}







 public HttpResponseMessage AddCategory(JOBCATEGORY类别) )
{
HelpDeskRepository.AddCategory(category);
var response = Request.CreateResponse < JOBCATEGORY > (HttpStatusCode.Created,类别);
string uri = Url.Link(DefaultApi,new {id = category.CategoryId});
返回回复;
}















当我运行这个我只能发布票价值(这只是第一个帖子方法正在运行)。第二个不工作。





任何人都可以帮我这样做。


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:


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;
       }




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.

.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:


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;
       }




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.