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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:18:25+00:00 2026-05-25T01:18:25+00:00

I am attempting to send some data via JSON to a MVC controller action:

  • 0

I am attempting to send some data via JSON to a MVC controller action:

For some reason, this works:

var items = [];
$("input:checked").each(function () { items.push($(this).val()); });

//This works
$.ajax({
    type: "POST",
    url: url,
    data: { listofIDs: items, personID: personID},
    dataType: "json",
    traditional: true,
    success: function() {
        //Rebind grid
    }
});

//This listofIDs is ALWAYS null !? (longhand for `$.getJSON` ?)
$.ajax({
    url: url,
    dataType: 'json',
    data: { listofIDs: items, personID: personID },
    success: function () {
        //Rebind grid
    }
});

So why does it work at the top, but the bottom it is always null? The same code is used to build items !?

edit: controller method

public ActionResult AddJson(List<int> listofIDs, int personID)
        {
            if (listofIDs==null || listofIDs.Count < 1)
                return Json(false, JsonRequestBehavior.AllowGet);

...
//Add something to database
//Return true if suceeed, false if not
}

edit: so I ended up solving it by just turning the array into a string and sending it that way. That way I was able to send more than just the array variable.

var items = $(':input:checked').map(function () { return $(this).val();}).toArray();
            var stringArray = String(items);

$.ajax({
                url: url,
                dataType: 'json',
                data: { listOfIDs: stringArray, personID: personID },
                success: function () {
//rebind grid
                }
            });

Note no POST type needed to be set.

  • 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-25T01:18:25+00:00Added an answer on May 25, 2026 at 1:18 am

    Without type: "POST" it defaults to GET (according to the docs), which your server side code is probably not expecting.

    Also, you could get a list of the values with…

    var items = $(':input:checked').map(function() {
        return $(this).val();
    }).toArray();
    

    jsFiddle.

    Not sure if it’s better though. Just an idea I had 🙂

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

Sidebar

Related Questions

I am attempting to use JSON to send data between the browser and my
I am attempting to send Base64 image data via ajax to Server. Sometimes all
I'm attempting to send HTML formatted emails using C# 3 via Outlook.MailItem Outlook.MailItem objMail
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to send data to a server in a separate thread and
I'm attempting to send a JSON encoded MongoDB object back in my HTTP response.
I am attempting to pull out some items from a mysql DB and place
I'm attempting to use the rest-client gem to post something, but for some reason,
This is the method I am attempting to use whilst trying to send a
I'm attempting to send lat and lon along with a webcam image and some

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.