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 9227981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:12:48+00:00 2026-06-18T05:12:48+00:00

I have a web api method defined as follows: [HttpPost] public void Post(Input model)

  • 0

I have a web api method defined as follows:

[HttpPost]
public void Post(Input model)
{
    ...
}  

With Input model like this:

public class Input
{
    public string Id { get; set; }
    public object Extra { get; set; }
}

What I want to do is pass a valid JSON object as the extra parameter like the following example with jQuery:

$.post(
    'http://localhost/api/myController',
    { 
        id: 'someId',               
        extra: { 
            tags: ['a', 'b'],
            anotherValue: 'hello',
            oneMore: { 
                foo: 'bar'
            }
        }
    });

Id comes correctly into my model.Id property. However, the extra property comes as an {object} and since I don’t know whats in there I cannot deserialize it in any way.

I tried making it dynamic and/or casting it to dynamic/ExpandoObject/Dictionary without success. I know that I can probably make it work if I just receive a raw HttpRequestMessage and handle it myself. Hoever I would rather not do it and rely in all validations that .NET has in place.

Is it possible?

Thanks

EDIT 1: After testing some more alternatives I found that the extra property does not have any real value and it’s just initialized as a new object(). Looks like the default model binder implementation does not deal with dynamic JSON (at least not like this) and simply call the default constructor of the model property that it cannot deals with.

  • 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-18T05:12:50+00:00Added an answer on June 18, 2026 at 5:12 am

    Defining your property as object should work or if you want to be explicit you give your Extra property the type JObject.

    However the problem is with $.post request. In order to post complex data to a web.api method and allow the model binding you need to do two things:

    • set the content type to ‘application/json’
    • and send the data as JSON with calling JSON.stringify on it

    But with $.post you cannot specify the content type so you need to use $.ajax:

    So the following call should post the data to your action:

    $.ajax({
        url: 'http://localhost/api/myController',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(
        { 
            id: 'someId',               
            extra: { 
                tags: ['a', 'b'],
                anotherValue: 'hello',
                oneMore: { 
                    foo: 'bar'
                }
            }
        })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using the New MVC Web Api I have something like this: public class
I have the following Web API method in an ApiController class: public HttpResponseMessage Post([FromBody]byte[]
I have a Portable Class Library (PCL) method like this: public async Task<string> GetLineStatuses()
I have a Web API controller that accepts an Inspection model, i.e. public class
I have a POST ASP.Net Web Api method adapted from A guide to asynchronous
I have made a web API class for my Customer model. I have the
I am currently working on MVC4 SinglePage Application. I have a Web Api method
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
Using the ASP.NET Web-Api, I have the following POST setup in my controller. When
I have the following action in my ASP.NET Web API: public IEnumerable<Car> carssOfUser(int id,

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.