Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have a web-api, 2 tables in my SQL DB, JT and Sales. Before I add() to the database I need the poster to specify first in the uri whether he/she wants to post to JT table or Sales. My problem is that my post method only accepts one model binding, it doesn't want two like as shown on my code below. It doesn't have errors but when I post with that logic in mind it returns an error in POSTMAN that It can't bind multiple parameters ('JT' and 'Sales') to the request's content.

Here is my code:
C#
[ResponseType(typeof(JT))]
public HttpResponseMessage PostJT(JT JT, Sales Sales, [FromUri] string tran)
        {
            try
            {
                if (ModelState.IsValid)
                {
                 if (tran == null)
                            {
                                return Request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized Access!");
                            }
                            else
                            {
                                switch (tran)
                                {
                                    case "JT": db.JTs.Add(JT); 
                                        break;
                                    case "sales": db.Sales_.Add(Sales);
                                        break;
                                }
                            }
                            db.SaveChanges();
                            return Request.CreateErrorResponse(HttpStatusCode.OK, "Added!");
                        }
//below are just elses with return messages.
Posted

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