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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:19:55+00:00 2026-05-26T21:19:55+00:00

Please see this pic: I have a one to many relationship between eg. Person

  • 0

Please see this pic:

enter image description here

I have a one to many relationship between eg. Person and Address. Problem here is that it is a “add” form and so even master record is not in database. How should I design this UI and implementation? What if the person clicks “save address” in popup. What personId should I associate that particular address with? In Asp.Net I would have stored it in ViewState and so this problem wouldn’t have come. But how do I do this Asp.Net MVC 3.0? Should I store it in Session and then when finally “save” is clicked on main form I retrieve all address from session and save it. This looks to be a very hackish approach because what if the person open same form in two tabs? Should I keep creating hidden fields on the child form and store it there in CSV format or something? This works but will result in an ungly javascript code.

I hope I am clear on my question. If not please let me know. How do you handle this in Asp.Net MVC?

Thanks.

  • 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-26T21:19:56+00:00Added an answer on May 26, 2026 at 9:19 pm

    When the person clicks “Save Address” in the popup, use some javascript to add the entry to the underlying main page, both as text and a set of hidden fields containing the data. When the form is finally posted back, those hidden inputs can be turned into the related data for the main record.

    It will look something like this when you are done.

    <div class="addresses">
        <div class="address">
            123 Street, Foo City, Idaho, 22222-2222
            <a href="#" class="delete-address">Delete</a>
            <input type="hidden" name="Addresses[0].Street" value="123 Street" class="address-start" />
            <input type="hidden" name="Addresses[0].City" value="Foo City" />
            <input type="hidden" name="Addresses[0].State" value="Idaho" />
            <input type="hidden" name="Addresses[0].Zip" value="22222-2222" />
        </div>
        ...
    </div>
    
    <!-- so you can remove them once added -->
    <script type="text/javascript">
        $(function() {
             $('.delete-address').click( function() {
                   $(this).closest('.address').remove();
             });
        });
    </script>
    

    Note this assumes your view model has a List<Address> named Addresses with the appropriate properties on the Address class. Note that the indices need to be consecutive. You can use a bit of javascript to update these upon form submit.

     $('form').submit( function() {
          $('.address-start').each( function(idx) {
              var prefix = 'Addresses[' + idx + '].';
              $(this).attr('name',prefix + 'Street')
                     .next(':hidden')
                     .attr('name',prefix + 'City' )
                     .next(':hidden')
                     .attr('name',prefix + 'State' )
                     .next(':hidden')
                     .attr('name',prefix + 'Zip' );
          });
          return true;
     });
    

    Note also that if you do this sort of thing when editing and use something similar, you will probably want to add a Deleted property to the Address class and merely hide the address being deleted, while setting the corresponding Deleted input to value True so that you know it should be removed on post. I’ve shown it here without indices as on create they will be bound in the order they occur. On edit if you add one, you may need to calculate the correct index for the new elements.

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

Sidebar

Related Questions

Please see this jsFiddle: https://jsfiddle.net/Wmq6f/ I have a textarea that has a background image,
Please see this This Image for a picture of the problem. I have a
Please see the back trace below, I don´t think I have seen this before
It seems that i cannot access $(this) inside jquery ajax success function. please see
Please see this: http://jsbin.com/igeqa here, i am simply using alert ( tableObj.childNodes.length ); and
Please see this fiddle for my situation. Essentially, I have a floating span which
Please see this fiddle (the result window should be made large). When one of
please see this question. The initial question was solved, and I have a method
Please see this page for reference: test page I am designing a site that
Please See this: http://img405.imageshack.us/img405/2008/rolloversummaryschedule.jpg How can i create a window that holds Patient data

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.