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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:33:24+00:00 2026-05-31T02:33:24+00:00

On one of the forms I am working on, if the user selects DropDownList

  • 0

On one of the forms I am working on, if the user selects DropDownList “Type”, based on the value selected, I would show Dynamically a set of other DropDownLists.

For instance, Types: Car, Apartment
Selecting “Car”, would dynamically add two new DropDownLists “Price” & “Model”.
Selecting “Building”, would dynamically add two new DropDownLists “Area” & “Floor”

My question is how to handle the posted data to server? I would typically receive the form’s fields and they get “model bound” automatically. But what about those dynamic fields that were added on the page based on user’s selection? How will I retrieve them inside the Action?

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-31T02:33:26+00:00Added an answer on May 31, 2026 at 2:33 am

    Ah misunderstood this.

    If you know what Dropdowns can potentially be added, I would always just have a value on your model. MVC will set them as a default value if nothing is received.

    EDIT: You can still access the forms collection in a more raw way from withing controllers using

    Request.Form.Keys
    Request.QueryString.Keys
    
    Request["ExpectedDropdownName"]
    

    Of course these will be all values posted by your form so you will need a way to recognise one of your dropdowns like a prefix or something. For example

       foreach (var key in Request.Form.AllKeys.Where(k => k.StartsWith("dynamic-dropdown-"))
       {
           var selectedValue = Request[key];
       }
    

    I still don’t really understand how you intend to process the dynamic dropdowns if you don’t know what they will be and this can cause some issues and will make validation entirely dynamic and client side (not 100% safe). That could present some security issues as well, but there are some sceanarios where you might use this and I’ll assume you have one of them.

    If that’s not the case, don’t forget that just because a Model has a property, it doesn’t have to be posted back at all.

    You could do:

    public class MyModel
    {
        [Required]
        public string FirstName { get; set; }
    
        public string PossibleDropdown1 { get; set; }
    
        public string PossibleDropdown2 { get; set; }
    }
    

    The controller will do it’s best to populate the model, but if you don’t pass some fields back from the form, they will just be null and the action will still work.

    I have also implemented much more complex scenarios like this using objects that are children of the parent model and all nullable. That requires a bit of fancy work around ajax calls to EditorTemplates in mock Views to ensure the prefixing is right for MVC to parse, but I won’t go into that here.

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

Sidebar

Related Questions

I've been working a lot with asp.net web forms and one think that I
I've started working on some enhancements to an ASP.NET web forms e-commerce project, one
In one of my forms I would like to have a dropdown (sfWidgetFormChoice) where
I am working on scripts that would generate a list of radiobuttons. The user
I'm working with Windows forms. I want an event to fire when the user
The form below is working as I want except for one thing. When I
I'm working with Netbeans IDE in Java. I've a form with one JPanel. Each
I am working on a pair of form fields the directly effect one another.
I'm using Rails 3.2, Carrierwave and simple_form. Currently, everything is working fine with one
Here is my problem. If I use only one Windows Forms project and call

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.