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

The Archive Base Latest Questions

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

I’m having a huge amount of trouble passing a Javascript array to my controller

  • 0

I’m having a huge amount of trouble passing a Javascript array to my controller in MVC 3. I keep getting null values and feel like I have tried every way of passing the array. Below is the JavaScript, the relevant view models for the Questions and the controller signature. I’d appreciate any help. I’m not getting any errors in my JavaScript and I think i must be missing something fundamental.

The values for id and response-id are being received correctly at the controller.

javascript

$("#form-submit-scores").submit(function () {

        var question = [],
        var item = [],

        $('.questionRow').each(function (index) {
            question[index] = new Array();
            var fullQuestionId = $(this).attr('id');
            var fullQuestionParts = fullQuestionId.split('-');
            question[index].QuestionId = fullQuestionParts[fullQuestionParts.length - 1];
            question[index].QuestionScore = $('.scoreBoard').val();
        });

        $('.itemRow').each(function (index) {
            item[index] = new Array();
            item[index].ItemId = $(this).attr('id');
            item[index].ItemScore = $('.scoreBoard').val();
        });

        var url = "/ctr/SaveResponse",
            data = {
                Id: $('#id').val(),
                ResponseId: $('#response-id').val(),
                Questions: question,
                Items : item
            },

        if (isSubmitScores) {
            url = "/ctr/SubmitResponse"
        }

        $.ajax({
            url: url,
            type: 'Post',
            data: data,
            traditional:true,
            datatype: "json",
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                if (!result.Success) {

....
....
....

viewmodels

public class SubmitResponseViewModel
    {
        public int Id { get; set; }
        public int ResponseId { get; set; }
        IEnumerable<SubmitResponseScoresQuestionViewModel> Questions {get;set;}
        IEnumerable<SubmitResponseScoresItemViewModel> Items { get; set; }
    }



public class SubmitResponseScoresQuestionViewModel
    {
        public int QuestionId { get; set; }
        public decimal? QuestionScore { get; set; }
    }

controller signature

public JsonResult SubmitResponseScores(SubmitResponseScoresViewModel model)

So as I said above, my model now contains the correct values for Id and response-id but null values for Questions and Items. I have confirmed that my data is being populated in the AJAX call so i’m thinking that I’m not providing the data in the appropriate format for the controller.

EDIT:1

Chrome JS Debugger: AJAX Data object

  JSON.stringify(data, null, 2)
"{
  "Id": "1027",
  "ResponseId": "26",
  "Questions": [
    {
      "QuestionId": "7",
      "QuestionScore": "0"
    },
    {
      "QuestionId": "2",
      "QuestionScore": "0"
    },
    {
      "QuestionId": "1",
      "QuestionScore": "0"
    }
  ],
  "Items": [
    {
      "ItemId": "434",
      "ItemScore": "0"
    }
  ]
}"
  • 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-18T06:57:26+00:00Added an answer on June 18, 2026 at 6:57 am

    You want to serialize your array to JSON using JSON.stringify
    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify

    1) install Json.net in Nuget to include the JsonFilter notation

    PM> Install-Package Newtonsoft.Json
    

    2) place a Json Filter annotation on your action method

    [JsonFilter(Param = "attributes", JsonDataType = typeof(AttributeViewModel[]))]
      JsonResult SubmitResponseScores(SubmitResponseScoresViewModel model)
    

    3) In your ajax call:

        data:  JSON.stringify(data), 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am confused How to use looping for Json response Array in another Array.
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.