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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:11:04+00:00 2026-05-12T00:11:04+00:00

I’m using jQuery to make an Ajax call using an Http Post in ASP.NET

  • 0

I’m using jQuery to make an Ajax call using an Http Post in ASP.NET MVC. I would like to be able to pass a Dictionary of values.

The closest thing I could think of was to pass in a multi-dimensional array of strings, but the result that actually gets passed to the ActionResult method is a single dimensional string array containing a string concatenation of the “key/value” pair.

For instance the first item in the below “values” array contains the below value:

"id,200"

Here’s an example of my ActionResult method:

public ActionResult AddItems(string[] values)
{
    // do something
}

Here’s an example of how I’m calling the method from jQuery:

$.post("/Controller/AddItems",
    {
        values: [
            ["id", "200"],
            ["FirstName", "Chris"],
            ["DynamicItem1", "Some Value"],
            ["DynamicItem2", "Some Other Value"]
        ]
    },
    function(data) { },
    "json");

Does anyone know how to pass a Dictionary object from jQuery to the ActionResult method instead of an Array?

I would really like to define my ActionResult like this:

public ActionResult AddItems(Dictionary<string, object> values)
{
    // do something
}

Any suggestions?

UPDATE: I tried passing in a comma within the value and it basically just makes it impossible to actually parse the key/value pair using string parsing.

Pass this:

values: [
    ["id", "200,300"],
    ["FirstName", "Chris"]
]

results in this:

values[0] = "id,200,300";
values[1] = "FirstName,Chris";
  • 1 1 Answer
  • 1 View
  • 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-12T00:11:04+00:00Added an answer on May 12, 2026 at 12:11 am

    At last I figured it out!! Thanks for the suggestions everyone! I finally figured out the best solution is to pass JSON via the Http Post and use a custom ModelBinder to convert the JSON to a Dictionary. One thing I did in my solution is created a JsonDictionary object that inherits from Dictionary so that I can attach the custom ModelBinder to the JsonDictionary type, and it wont cause any conflicts in the future if I use Dictionary as a ActionResult parameter later on for a different purpose than JSON.

    Here’s the final ActionResult method:

    public ActionResult AddItems([Bind(Include="values")] JsonDictionary values)
    {
        // do something
    }
    

    And the jQuery “$.post” call:

    $.post("/Controller/AddItems",
    {
        values: Sys.Serialization.JavaScriptSerializer.serialize(
                {
                    id: 200,
                    "name": "Chris"
                }
            )
    },
    function(data) { },
    "json");
    

    Then the JsonDictionaryModelBinder needs to be registered, I added this to the Application_Start method within the Global.asax.cs:

    protected void Application_Start()
    {
        ModelBinders.Binders.Add(typeof(JsonDictionary), new JsonDictionaryModelBinder());
    }
    

    And, finally here’s the JsonDictionaryModelBinder object and JsonDictionary object I created:

    public class JsonDictionary : Dictionary<string, object>
    {
        public JsonDictionary() { }
    
        public void Add(JsonDictionary jsonDictionary)
        {
            if (jsonDictionary != null)
            {
                foreach (var k in jsonDictionary.Keys)
                {
                    this.Add(k, jsonDictionary[k]);
                }
            }
        }
    }
    
    public class JsonDictionaryModelBinder : IModelBinder
    {
        #region IModelBinder Members
    
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.Model == null) { bindingContext.Model = new JsonDictionary(); }
            var model = bindingContext.Model as JsonDictionary;
    
            if (bindingContext.ModelType == typeof(JsonDictionary))
            {
                // Deserialize each form/querystring item specified in the "includeProperties"
                // parameter that was passed to the "UpdateModel" method call
    
                // Check/Add Form Collection
                this.addRequestValues(
                    model,
                    controllerContext.RequestContext.HttpContext.Request.Form,
                    controllerContext, bindingContext);
    
                // Check/Add QueryString Collection
                this.addRequestValues(
                    model,
                    controllerContext.RequestContext.HttpContext.Request.QueryString,
                    controllerContext, bindingContext);
            }
    
            return model;
        }
    
        #endregion
    
        private void addRequestValues(JsonDictionary model, NameValueCollection nameValueCollection, ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            foreach (string key in nameValueCollection.Keys)
            {
                if (bindingContext.PropertyFilter(key))
                {
                    var jsonText = nameValueCollection[key];
                    var newModel = deserializeJson(jsonText);
                    // Add the new JSON key/value pairs to the Model
                    model.Add(newModel);
                }
            }
        }
    
        private JsonDictionary deserializeJson(string json)
        {
            // Must Reference "System.Web.Extensions" in order to use the JavaScriptSerializer
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            return serializer.Deserialize<JsonDictionary>(json);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 227k
  • Answers 227k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Because the %s format specifier tells printf that the argument… May 13, 2026 at 1:21 am
  • Editorial Team
    Editorial Team added an answer These are different operations. In Python, you need to use… May 13, 2026 at 1:21 am
  • Editorial Team
    Editorial Team added an answer Its important to analyze Complexity in any Language be it… May 13, 2026 at 1:21 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.