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

  • Home
  • SEARCH
  • 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 8094473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:48:28+00:00 2026-06-05T20:48:28+00:00

I am having problems passing a javascript array to an MVC3 controller, not sure

  • 0

I am having problems passing a javascript array to an MVC3 controller, not sure what I am doing wrong but this code does work with standard WCF service.

$(function () {
    $("button").click(function () {
        Poster();
    });
});

function Poster() {
    var data = [];
    data.push(new WidgetProperty("test1", "value1"));

    alert(data.length);

    $.post("Home/Test", {test : data});
}

function WidgetProperty(name, value) {
    this.Name = name;
    this.Value = value;
}

and controller is

[HttpPost]
public ActionResult Test(WidgetProperty[] test)
{
    return View("About");
}


public class WidgetProperty
{
    public string Name { get; set; }
    public string Value { get; set; }
}

Any ideas why the object that comes to the controller has null values for the properties? Checked with fiddler and it appears it passing the correct values.

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-05T20:48:30+00:00Added an answer on June 5, 2026 at 8:48 pm

    You should use JSON.stringify() on your data before you post it, and since you know the data type is JSON, it is best to specify that the data being posted is JSON.

    $.post("Home/Test", {test : JSON.stringify(data) }, "json");
    

    Live DEMO

    Edit:

    I researched this a little more and it seems that you need to include contentType: "application/json" in order for this to work in mvc3:

    $.ajax({
         type: "POST",
         url: "Home/Test",
         data: JSON.stringify(data),
         success: function(data){},
         dataType: "json",
         contentType: "application/json"
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having problems passing PHP Strings to Javascript functions, I'v read a number of
I am having problems passing javascript values between frames in chrome. In other browsers
I'm having problems passing parameters (in this case, @plan_id) to the next page (new_user_url).
I'm having a problem with the inArray function not sure why. I'm passing a
I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlencode on
I'm having problems passing some connection info to a runnable thread(using rabbitmq, but I
I am having problems with passing arguments to new threads, I have the following
I'm having some problems with Jquery UI Dialog and TinyMCE. Passing data to a
I am having some problems parsing this piece of XML using SimpleXML. There is
I'm having problems with parsing a decimal string to a byte. This is the

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.