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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:01:04+00:00 2026-06-04T07:01:04+00:00

I am attempting to pass back an object with a property that is a

  • 0

I am attempting to pass back an object with a property that is a collection of objects but when using the serialized form as the data attribute in my Ajax post the collection is empty (null). Is this the wrong way to pass back a object that contains a list as a property or is there something simple I am over-looking? When I step into the controller action I can see that I have the Holder.Id attribute populated but MyList is empty.

I have tried making the contentType: ‘application/json’ with no help. I would like to have the full object as the payload for Ajax post instead of each individual item in the collection. When calling Ajax with each individual item it does work and I may have to use that method.

Simple POCO objects:

public class Holder
{
    public int Id { get; set; }
    public List<Contained> MyList { get; set; }
}

public class Contained
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Controller methods:

    [HttpGet]
    public ActionResult Edit()
    {
        List<Contained> contained = new List<Contained>();
        contained.Add(new Contained{Id=123, Name="123Name"});
        contained.Add(new Contained{Id=456, Name="456Name"});
        return View(new Holder { Id = 1001, MyList = contained });

    }

    [HttpPost]
    public JsonResult Edit(Holder holder)
    {
        return Json("Succeeded");
    }

Html Markup:

@model Compeat.MyMvcApp.Controllers.Holder
@{
     ViewBag.Title = "Edit";
}
<script type="text/javascript">
$(document).ready(function () {
    $("#btnAdd").click(function () {
        var coll = [];
        var newName = $("#txtAddNameToList").val();
        coll.push(newContainedJson(999, newName));
        $("#MyList").val(coll);
        var frmElems = $("form").serialize();
        console.log(coll);
        $.ajax({
            type: "POST",
            data: coll,
            url: "Edit",
            dataType: "json",
            success: function (data) { alert('worked!'); },
            error: function (data) {
                alert('error: ' + data.responseText);
            }
        });
    });

    function newContainedJson(id, name) {
        return { "Id": id , "Name": name };
    }
});
</script>
<ul>
@foreach (var o in Model.MyList)
{
    <li>@o.Name</li>
}
</ul>
@{ using (Html.BeginForm())
   {
@Html.HiddenFor(e => e.Id)
<input type="hidden" name="MyList" id="MyList" value="" />
<input type="text" id="txtAddNameToList" name="txtAddNameToList" />
<input type="button" id="btnAdd" value="Add Name" />
}}
  • 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-04T07:01:05+00:00Added an answer on June 4, 2026 at 7:01 am

    Use the JQuery below and set a breakpoint in your controller.

     $("#btnAdd").click(function () {
    
    
    
            var data = {}
            data.Id = 9;
            data.MyList = [];
            data.MyList.push({ 'Id': 99, 'Name': 'Dude' });
            data.MyList.push({ 'Id': 990, 'Name': 'Dude2' });
    
            $.ajax({
                type: "POST",
                data: JSON.stringify(data),
                url: "Home/Index",
                dataType: "json",
                contentType: 'application/json',
                success: function (data) { alert('worked!'); },
                error: function (data) {
    
                }
            });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to pass back a Node type from this function, but I
i have been attempting to pass an object into a function that belongs to
I am attempting to pass in a connection string to an SqlConnectionStringBuilder object, but
hey i'm attempting to pass xml values using this hidden form: <form method='post' action='addholiday.php'
I am attempting to create a new Case object using the REST API but
I'm attempting to pass the lat, long using HTML5 geolocation to automatically populate two
I am attempting to dynamically generate cube-maps in OpenGL using a multi-pass rendering system.
Im attempting to pass an array that is created in one class into another
I'm attempting to pass a team name, and the number of penalties that team
In my process I'm attempting to launch appB from appA using startActivityForResult and pass

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.