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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:15:56+00:00 2026-05-24T03:15:56+00:00

I have a model public class Foo{ public int Id{get;set;} public string Name {get;

  • 0

I have a model

  public class Foo{
     public int Id{get;set;}
     public string Name {get; set;}
     public DateTime Date {get; set;}
     public bool IsActive {get;set;}
     public List<Item> Items {get;set;}
  }

 public class Item{
    public int Id {get;set;}
    public string Name {get; set;}
    public Foo Foo {get;set;}
 }

And in my javascript I do that:

var items = new Array();
$("#itemsSelector").each(function () {
   items.push({Id: $(this).val(), Name: $(this).text() })
}

var id = $("#id").val();
var title = $("#title").val();
var date = $("#dateTimePicker").val();
var isActive = $("#msActive").val();

$.post("SaveFoo", {Id: id, Name:title, Date:date, IsActive: isActive, Items:items })

Action method signature looks like that:

 [HttpPost]
 public JsonResult SaveFoo(Foo foo) {
      // Now. here it passes correct Id, Name, Date and bool parameter
      // And even passes the correct number of Foo.Items
      // The only thing that bothers me -
      // all the properties of every Item is either null or zero!
 }

Why is that happening? What am I doing wrong? How to pass the objects array to the action? I’ve tried to use jquery.serialize() and serializeArray()and even $.toDictionary() method described here.

That’s not helping

  • 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-24T03:15:57+00:00Added an answer on May 24, 2026 at 3:15 am

    Have you tried a JSON request? It works much better with complex properties and collections:

    var items = new Array();
    $('#itemsSelector').each(function () {
        items.push({ id: $(this).val(), name: $(this).text() });
    }
    
    var id = $('#id').val();
    var title = $('#title').val();
    var date = $('#dateTimePicker').val();
    var isActive = $('#isActive').val();
    
    $.ajax({
        url: 'SaveFoo',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({
            id: id, 
            name: title, 
            date: date, 
            isActive: isActive, 
            items: items 
        }),
        success: function(result) {
    
        }
    });
    

    And if you need to support older browsers you might need to include the json2.js script so that the JSON.stringify function works.

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

Sidebar

Related Questions

I have this model: public class Package { public string CustomerName { get; set;
I have this Model public class SalesModelView { [Key] public int SaleId { get;
I have model that looks like this: public class Lesson { public int Id
I have a set of model classes from another section of the application that
I have the following MyType::Is_Inst () function which is throwing an invalid memory access
I have an extremely simple example trying to use Data Annotations with unobtrusive javascript
I have enabled unobtrusive client side validation in my app, and I have (something
I am using a model in Play like this: package models; import java.util.*; import
tl;dr version: Is there a way to force a strict mode for JAX-WS that
I am trying to understand why my Html.ListBoxFor() is not highlighting current selected items

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.