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

The Archive Base Latest Questions

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

I have the following class… public class Product { public int Id { get;

  • 0

I have the following class…

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IList<SizeOption> SizeOptions { get; set; }
    public IList<ColorOption> ColorOptions { get; set; }
    public IList<Product> SimilarProduct  { get; set; }
}

I won’t elaborate on the details of each of those additional classes. What is important is that a Product contains multiple properties that are child collections.

I’m developing an ASP.NET MVC3 (Razor) web application to help manage these products.

The UI must function in such a way that I have one area for editing the low level product details (Id, Name, Price, etc.) followed by separate areas below for each child collection on Product. (the client wants to manage everything about a product in one screen).

Those areas each have an “Add” button, which creates a new dynamic row with textboxes and various select/checkbox elements so the user can specify options for that object. The user can add/remove these rows of child objects as much as they need to…this is all happening client side with the help of jQuery. Nothing is saved until they submit the form.

What I’m having trouble with is how best to design the layers involved.

Currently, I have a partial view for the Edit Form which is used by the Add Product and Edit Product views. This partial view leverages JavaScript functions to create the dynamic rows. The markup for those dynamic rows is created in these functions in this fashion:

var newRow = $('<tr>').append(...) // etc.
table.append(newRow);

The problem with this approach, is that when I load the Edit Product view, I’m writing the existing child rows using MVC by iterating over the Model’s child collections and outputting HTML markup for the rows. For example…

@foreach(var sizeOption in Model.SizeOptions)
{
     <tr>... etc.</tr>
}

This means that I’m duplicating the UI for the rows…I don’t like this. I’ve tried serializing the Model to Json, and calling the client functions based on the data in the Json object, to keep the UI code in one place, but this produces visible latency, which I also do not like.

Lastly, to keep MVC Happy, when the form is finally posted, I iterate the HTML tables and update the Name attributes of the form elements to be in the form of Product.SizeOptions[0].PropertyName so that the MVC View Engine will give a fully hydrated View Model as an argument for my Action methods.

Ultimately I’m looking for advice on how to handle this type of dynamic adding/editing in a scalable and maintainable fashion.

Thanks in advance for the help!

  • 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-04T11:55:03+00:00Added an answer on June 4, 2026 at 11:55 am

    You might find the following blog post interesting. In it Steven Sanderson illustrates a nice technique that allows to dynamically edit a variable length lists in ASP.NET MVC. It uses a custom helper which allows for generating proper names of the input fields so that the default model binder is able to successfully retrieve the values when the form is submitted. As far as adding a row is concerned, he uses AJAX to invoke a controller action which renders a partial view which simply gets added to the DOM.

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

Sidebar

Related Questions

I have the following class: public class Movie { string Name get; set; string
Lets say i have following class public class abc { int id; string name;
Have the following: class Hal { public int zip { get; set; } public
I have 3 following classes: public class BaseProperty1{ public string Property1 {get; set;} }
I have the following class public class Car { public Name {get; set;} }
I have the following class public class MenuVeiculo { public string Nome { get;
I have the following class A. public class A { public string Name {
I have following structure: class Employee { public long Id { get; set; }
I have following class class hash_key { public: int get_hash_value(std::string &inStr, int inSize) const
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int

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.