Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:30+00:00 2026-06-17T18:23:30+00:00

I am trying to call a POST API controller. The controller gets called but

  • 0

I am trying to call a POST API controller. The controller gets called but the complex object comes in empty. I have ran Fiddler and the object is even coming through populated there. What am I doing wrong?

My C# object

public class RegisterUser
{
    public Guid PersonId { get; set; }
    public string Email { get; set; }
    public string Business { get; set; }
    public string EmployeeNumber { get; set; }
    public string UserName { get; set; }
}

API Post Controller

public HttpResponseMessage Post(RegisterUser user)
{
   //This is where the problem is. Everything in user is null 
   //even though I can see it coming through on Fiddler.
}

Javascript code

function User(personId, userName, email, business, employeeNumber) {
   this.PersonId = personId;
   this.Email = email;
   this.Business = business;
   this.EmployeeNumber = employeeNumber;
   this.UserName = userName;
}

function RegisterUser(url) {
   var createdUser = new User("b3fd25ba-49e8-4247-9f23-a6bb90a62691", "username", "email", "business", "56465");
   $.ajax(url, {
       data: JSON.stringify({ user: createdUser }),
       type: "post",
       contentType: "application/json"
  });
}

Web API Route Config

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "RegisterApi",
            routeTemplate: "api/{controller}/{user}"
        );
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:23:32+00:00Added an answer on June 17, 2026 at 6:23 pm

    createdUser already contains the data needed by Web.Api in the correct format there is no need to wrap it inside an user property which confuses the model binder.

    Just write data: JSON.stringify(createdUser) and it should work fine:

    function RegisterUser(url) {
       var createdUser = new User("b3fd25ba-49e8-4247-9f23-a6bb90a62691", "username", "email", "business", "56465");
       $.ajax(url, {
           data: JSON.stringify(createdUser),
           type: "post",
           contentType: "application/json"
      });
    }
    

    The principles of the model binding are simple until you have matching property names and object structure in your JS and C# objects and it should work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The API I'm trying to call requires a POST with an empty body. I'm
I'm trying to call a API with a POST request. But my Chrome Inspector
I was trying to call eBay FindProducts API using AJAX ( post request) but
I have been trying to make wall post from multiple pages but when i
trying to call ASP.NET 4 Web API from iOS using RestKit but the serialised
I am trying to do an API call via a SOAP POST and I
I am trying to run a system call which will post an activity to
I am trying to use relative url with a post ajax call as follows:
I am trying to call c# function from javascript the code i have tried
I'm trying to post a JSON object through a POST. I'm trying to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.