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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:24:40+00:00 2026-05-18T06:24:40+00:00

In my object graph, I have a standard parent + children relationship. Say something

  • 0

In my object graph, I have a standard parent + children relationship. Say something like,

Cat.Kittens = new HashSet<Cat>();

When I have a form for a new Cat, I want to add zero-or-many kittens prior to clicking the save button. Since it’s a new Cat, I also don’t want to post the kitten to the server yet (i.e. using AJAX or the like; I just want to do one big dump to the server with the save button). I’m trying to figure out the best way to do this with some efficiency but am coming up short on Google. Someone has to have done this already.

I’m less concerned about whether the parent Cat is new or not; if I have to push the kitten addition off to an Edit form, so be it. The issue for me is how to dynamically add multiple kittens on the client and subsequently be able to massage the collection in the controller prior to storing the data.

Any ideas? Good examples? jQuery + asp.net mvc 2 is the stack.

Thanks in advance!

  • 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-18T06:24:40+00:00Added an answer on May 18, 2026 at 6:24 am

    It can be done in one form I have done this where I will keep a blank kitten input form hidden on the page then copy it with jquery when the client says add another kitten.
    The controller is where it gets a little tougher

    public class Cat
    {
        public string name { get; set; }
        public List<Kitten> Kittens { get; set; }
    
    }
    
    public class Kitten
    {
        public int id { get; set; }
        public string color { get; set; }
        public string CatName { get; set; }
    }
    

    Controller

           public ActionResult AddCat()
        {
            return View();
        }
    
        [HttpPost]
        public ActionResult AddCat(Cat c)
        {
            var sb = new StringBuilder();
            sb.Append(c.name);
            sb.Append("kittens are : " + Request.Form["color"]);
            return Content(sb.ToString());
        }
    

    View

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Kittens.Models.Cat>" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    AddCat
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <h2>
        AddCat</h2>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend>Fields</legend>
        <div class="editor-label">
            <%: Html.LabelFor(model => model.name) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.name) %>
            <%: Html.ValidationMessageFor(model => model.name) %>
        </div>
        <table id="kittenDest">
            <tr>
                <td colspan="2">
                    <input id="Button1" type="button" value="add Kitten" />
                </td>
            </tr>
        </table>
        <p>
            <input type="submit" value="Create" />
        </p>
        <table id="kittenForm" style="display: none;">
        <tr>
            <td>                
                <input id="color" name="color" value="" type="text" />
            </td>
        </tr>
    </table>
    </fieldset>
    <% } %>
    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Button1").click(function () {
                $("#kittenDest").append($("#kittenForm").html());
            });
        });
    </script>
    

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

Sidebar

Related Questions

So I have an object graph, let's just say it's an order. You have
Explanation: Let's say I have an object graph that's nested several levels deep and
I have an object graph that looks like this: class A () { int
I have a pretty sizeable object graph that I have serialized to a file
I have an object graph serialized to xaml. A rough sample of what it
I have this object graph, I want to map: abstract Account (username, password, ...)
The situation is this: You have a Hibernate context with an object graph that
I have a problem.... Lest say I have a class like this one: public
I have a graph object, that I need to serialize. Nomatter which members i
We have a big object graph with lot of properties and behavior in it.

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.