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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:57:05+00:00 2026-06-11T06:57:05+00:00

I need to pass an array of objects, which contain arrays, from javascript to

  • 0

I need to pass an array of objects, which contain arrays, from javascript to a MVC actionresult method. Basically I have a KeyValuePair whose key is an array of strings, and I need to pass back a list of these KeyValuePairs. In the code, I have a list of keys I’ve changed, and a JS object that holds key->value pairs. My javascript object that I try to pass back should be the same format as my class. I tried JSONing it as well, but no luck.

Thanks.

public class ChangedItem
{
    public IEnumerable<string> Key { get; set; }
    public int Value { get; set; }

    public ChangedItem()
    {
    }

    public ChangedItem(IEnumerable<string> key, int value)
    {
        Key = key;
        Value = value;
    }
}

[HttpPost]
public ActionResult UpdateResults(IEnumerable<ChangedItem> changedItems)
{
    return RedirectToAction("Index");
}

function getChangedItems() {
    var ChangedItems = new Array();
    for (var i = 0; i < _ChangedItemKeys.length; i++) {
        var ChangedItem = {};
        ChangedItem.Key = _ChangedItemKeys[i];
        ChangedItem.Value = _ChangedItems[_ChangedItemKeys[i]];
        ChangedItems[i] = ChangedItem;
    }
    return ChangedItems;
}

function submitNewVals() {
    $.ajax({
        url: '/Home/UpdateResults',
        type: 'POST',
        dataType: 'json',
        data:
        {
            changedItems: getChangedItems()
        }
    });
}

My request data is detailed below, and I get 6 items in my action result, its just that inside each of those items the key is null and value is 0:

changedItems[0][Key][]:BoxeR
changedItems[0][Key][]:Proleague
changedItems[0][Key][]:Total
changedItems[0][Key][]:2005
changedItems[0][Key][]:Quarter 2
changedItems[0][Key][]:Actual
changedItems[0][Value]:123
changedItems[1][Key][]:BoxeR
changedItems[1][Key][]:Proleague
changedItems[1][Key][]:Team
changedItems[1][Key][]:2005
changedItems[1][Key][]:Quarter 1
changedItems[1][Key][]:Actual
changedItems[1][Value]:123
changedItems[2][Key][]:BoxeR
changedItems[2][Key][]:Proleague
changedItems[2][Key][]:Team
changedItems[2][Key][]:2005
changedItems[2][Key][]:Quarter 1
changedItems[2][Key][]:Estimate
changedItems[2][Value]:123
changedItems[3][Key][]:BoxeR
changedItems[3][Key][]:Proleague
changedItems[3][Key][]:Team
changedItems[3][Key][]:2005
changedItems[3][Key][]:Quarter 2
changedItems[3][Key][]:Actual
changedItems[3][Value]:123
changedItems[4][Key][]:BoxeR
changedItems[4][Key][]:Proleague
changedItems[4][Key][]:Team
changedItems[4][Key][]:2005
changedItems[4][Key][]:Quarter 2
changedItems[4][Key][]:Estimate
changedItems[4][Value]:123

I tried playing around in fiddler and changing the request data format (using .Key[x], .Value), but nothing worked.

Thanks!

  • 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-11T06:57:06+00:00Added an answer on June 11, 2026 at 6:57 am

    The format should be like this:

    changedItems[0].Key[0]=BoxeR
    changedItems[0].Key[1]=Proleague
    changedItems[0].Key[2]=Total
    changedItems[0].Key[3]=2005
    changedItems[0].Key[4]=Quarter 2
    changedItems[0].Key[5]=Actual
    changedItems[0].Value=123
    ...
    

    See ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries for details.

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

Sidebar

Related Questions

I have an application in which I need to pass an array from C#
I have an array of objects in javascript and I know that I need
I need to pass a simple Javascript array to my wcf ajax webservice: var
I need to pass a variable which is captured from client side via jquery
I'm using ASP.NET MVC with XmlResult from MVCContrib. I have an array of Xxxx
I have a vector called actorVector which stores an array of objects of type
Is it possible to pass native JavaScript objects such as arrays and hash-map-like objects
I have a generated array which if hard coded passes the array objects to
In javascript I need to know if array contains value. Values are objects and
Possible Duplicate: when do we need to pass the size of array as a

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.