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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:36:07+00:00 2026-05-27T21:36:07+00:00

So, it pretty much is all in the title. Basically, I want to send

  • 0

So, it pretty much is all in the title. Basically, I want to send a JSON through JQuery from client to asp.net MVC. I’m wondering if it’s possible for it to receive (but not necessarily parse) any JSON I want to send from JQuery Ajax call, regardless of it’s type.. without me having a concrete type/model representation of it. (basically like a dynamic type?)

Doing this the regular way (with me declaring the passing argument as type Object) just brings about nulls, which was what I expected.

Basically, I want to do some kind of “reflection for JSON” type stuff when I receive it, and be able to get it’s properties through some kind of foreach loop and etc.

Thanks in advance. Any help would be great!

  • 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-05-27T21:36:07+00:00Added an answer on May 27, 2026 at 9:36 pm

    You could use an IDictionary<string, object> as action argument. Just write a custom model binder that will parse a JSON request into it:

    public class DictionaryModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
            {
                return null;
            }
    
            controllerContext.HttpContext.Request.InputStream.Position = 0;
            using (var reader = new StreamReader(controllerContext.HttpContext.Request.InputStream))
            {
                var json = reader.ReadToEnd();
                if (string.IsNullOrEmpty(json))
                {
                    return null;
                }
                return new JavaScriptSerializer().DeserializeObject(json);
            }
        }
    }
    

    which will be registered in Application_Start:

    ModelBinders.Binders.Add(typeof(IDictionary<string, object>), new DictionaryModelBinder());
    

    then you could have the following controller action:

    [HttpPost]
    public ActionResult Foo(IDictionary<string, object> model)
    {
        return Json(model);
    }
    

    to which you can throw anything:

    var model = {
        foo: {
            bar: [ 1, 2, 3 ],
            baz: 'some baz value'
        }
    };
    
    $.ajax({
        url: '@Url.Action("foo")',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(model),
        success: function (result) {
            // TODO: process the results from the server
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Title pretty much says it all. The web.config, unchanged from how VS2008SP1 generated it,
The title pretty much says it all. When I'm doing some reflection through my
The title pretty much says it all. I'm trying to use jQuery's ability (hoping
The title pretty much says it all. If I have something like (from PHP
The title of the question pretty much sums it all, I want to debug
The title basically sums it pretty much all up, with what I'm trying to
Title pretty much says it all. I want to use streeview for an area
I think the title pretty much says it all... I'm looking to implement an
The title pretty much says it all. Some caveats are: I need to be
The title pretty much says it all. I'm using a TClientDataset to store an

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.