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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:40:46+00:00 2026-05-21T22:40:46+00:00

This is my first SO question, and it’s less of a "how do I

  • 0

This is my first SO question, and it’s less of a "how do I do this" and more of a "what is the cleanest way to do this", because there are several approaches I see but none of them seem very appealing to me.

This is a bit of a complicated issue to describe. Essentially, I have an Add/Edit view that allows the user to edit the fields of some object. This object is pretty complex: it has some fields, and it has a sub-list of complex objects. Each complex object is about 40 fields large (mostly checkboxes, radio buttons and dates/times). I have represented this as a select list:


(source: fortheloot.com)

The Add button spawns the dialog with the various fields.

The question comes here. When the user accepts the dialog, and the dialog closes, I now have to store this data somewhere, so that the user can edit it further or add other sub-items before actually submitting the form.

The most obvious way to do this is to create a set of hidden fields for every sub-object. So, adding a sub-item would add 40-something hidden elements to the <form> element. Add 10 sub-items and you have 400 hidden fields. This will work fine, and will bind to this model if the fields are named properly:

public class AddEditModel
{
  [Display(Name = "ID")]
  public int? Id { get; set; }

  [Display(Name = "Name")]
  [Required]
  [StringLength(100)]
  public string Name { get; set; }

  public IList<EntryModel> Entries { get; set; }
  public class EntryModel { /* fields */ }
}

On the model binding side of things, this seems to look pretty good, but from the client side, I’m having to keep track of hundreds of DOM elements and this seems cumbersome to me. Loading and unloading the dialog’s various form elements from 40 other elements seems … like it could be better.

Ideally, I’d like to be able to just store the data as a javascript object on the <option> element using either data- HTML 5 attributes or jQuery’s data() function, which are really one and the same. This would make the javascript side of things much cleaner, but it wouldn’t automatically bind to the model on postback.

If there was a way to have the best of both worlds — storing a single JS object on the <option> element, or even a single <input type="hidden" /> element (per sub-item) — that would still bind to the model properly on postback, I’d feel this issue resolved.

  • 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-21T22:40:47+00:00Added an answer on May 21, 2026 at 10:40 pm

    You will still need an html field (type=hidden) in order to post this data back to the server. (You could use an ajax post but this probably isn’t a great idea)

    I would suggest designing a reasonable object model to contain these data structures, and serializing the object model each time you make a change it to json with stringify

    Then when you post back the form, the json will be sent to the server and you can deserialise the whole object model to a set of classes written in c# (which can mimic the object model you had in javascript) using the JavaScriptSerializer classes

    Edit:

    To deserialize a json string, you can use the following code:

    JavaScriptSerializer js = new JavaScriptSerializer(); 
    var c = js.Deserialize<MyClass>(json);
    return View(c);
    

    If you post back json as the post message body, (e.g. an $.ajax, or $.post method) then binding will occur automatically with MVC3, you simply have to specify the correct content type: application/json in the post; follow the link in my comment below for more details as to how this works.

    Martin

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

Sidebar

Related Questions

This is beyond both making sense and my control. That being said here is
I have found this example on StackOverflow: var people = new List<Person> { new
I want to use a temp directory that will be unique to this build.
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,
I was reading JavaScript: The Good Parts and the author mentions that JavaScript is
I'm trying to build a C++ extension for python using swig. I've followed the
Let say I have the following desire, to simplify the IConvertible's to allow me
I am attempting to pull some information from my tnsnames file using regex. I
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I have a new web app that is packaged as a WAR as part

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.