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 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 on mvc: public class User { public string Name {
I have a object model a bit like this: public class Foo { public
I'm used to the Java model where you can have one public class per
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
I have a method with the signature public void setFoo(int newFoo) in a model
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
I have a model Foo which have a ForeignKey to the User model. Later,
I have a class Foo with a field UpdateMe of type Confirmation as described
I have a model that has several properties. The properties can be primitive (String)
I have a model being populated by my data layer and then I have

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.