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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:42:55+00:00 2026-05-29T10:42:55+00:00

When I make my httppost call, i need to get the selected value and

  • 0

When I make my httppost call, i need to get the selected value and the id of a random number of dropdownlists in my view. The number of dropdownlists is random because they are created dynamically based on the selected value of another dropdownlist.
Example:
in dropdownlist 1 I select bmw. Then 3 dropdownlists are created, so the user can give each carmodel a rate value. Each dropdownlist has id= the model of the car and the options you can select is 1,2 and 3. If there was 4 carmodels of bmw, the options would then be 1,2,3 and 4 and so on…
When I make the httppost call, how do I in the controller run through all the dynammically created dropdownlist and check the value and id?

EDIT:
The controller of my index view:

public class BookingPensionController : Controller
{
    private DbEntities db = new DbEntities();
    EditBookingPensionViewModel objViewModel;
public ActionResult Index()
    {
        objViewModel = new EditBookingPensionViewModel
        {
            Booking = new Booking { BookingStartDate = DateTime.Today, BookingEndDate =  DateTime.Today, DateOfBooking = DateTime.Now }
        };
        objViewModel.deliveryTypes = new List<string>();
        int id = int.Parse(Session["id"].ToString());
        SelectList list;
        try
        {
            var deliverytypes = from d in db.DeliveryTypes
                                where d.Pension_ID == id
                                select d;
            foreach (DeliveryType item in deliverytypes)
            {
                objViewModel.deliveryTypes.Add(item.Titel);
            }
            ViewData["DeliveryTypes"] = objViewModel.deliveryTypes;

            objViewModel.customersToPension = new List<SelectListItem>();
            objViewModel.customersToPension = GetCustomersToPension(id);
        }
        catch (Exception ex)
        {

            throw;
        }

        int PensionId = int.Parse(Session["id"].ToString());
        objViewModel.CustomerValue = GetCustomersToPension(PensionId);

        return View(objViewModel);
    }

My Index view:

@model HundePensionBooking.ViewModels.EditBookingPensionViewModel
//Some code...
//And my script that retreives the customerinfo and creates the dropdownlists
$("#ddlCustomerId").change(function () {

         var id = $("#ddlCustomerId").val();
         getCustomerInfo(id);
         $('#customerinfo').load("@Url.Action("CustomerInfo", "BookingPension")");

         var ddlsource = "#ddlCustomerId";
         var ddltarget = "#ddlDogId";
         $.getJSON('@Url.Action("Dogs_SelectedCustomer")', { CustomerId: $(ddlsource).val() }, function (data) {


             $(ddltarget).empty();
             $("#tblRooms tr:gt(0)").remove();
             $.each(data, function (index, optionData) {
                 createDynamicTable($("#tblRooms"), optionData.Text, data.length);
             });
         });
     });
 });
 </script>
 <script type="text/javascript">
     function createDynamicTable(tbody, value, count) {
         if (tbody == null || tbody.length < 1) return;

             var trow = $("<tr>");
                 var cellText = value
                     var option;
                     $('<th scope="row" abbr="Model" class="spec">')
                        .addClass("tableCell")
                        .text(cellText)
                        .appendTo(trow);

                     var ddlselectroom = '<td class="spectd"><select class="selectbox" id=' + value + '>';
                     for (var d = 1; d <= count; d++) {
                         ddlselectroom += '<option value="' + d + '">Bur nr. ' + d + '</option>';
                     }

                     ddlselectroom += '</select></td>';
                     $(ddlselectroom).appendTo(trow);
             trow.appendTo(tbody);
     } 

//Some more code...
//And then the table which gets populated with the random number of dropdownlists:
<table id="tblRooms" width="100%">
    <tr>
</tr>
    </table>

The Viewmodel looks like this:

    public class EditBookingPensionViewModel
{
    public Booking Booking { get; set; }
    public IEnumerable<Customer> customerList { get; set; }
    public List<string> deliveryTypes { get; set; }
    public List<SelectListItem> customersToPension { get; set; }
    public Customer customer { get; set; }
    public CustomerInfoModel CustomerInfo { get; set; }

My partialview with the customerinfo looks like this:

@model HundePensionBooking.Models.Customer

So when I make the httppost call

<input type="submit" value="Create" />

I need to get all the data down to my database. Im not sure on how to do that but I assume I have to do it with my Create method in the controller class

[HttpPost]
    public ActionResult Create(EditBookingPensionViewModel model)
    {
        //SaveCustomer... From the CustomerInfo partialview
        //SaveBooking...From Index view
        //Save all the data from all the dropdownlists... from index view
    }
  • 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-29T10:42:55+00:00Added an answer on May 29, 2026 at 10:42 am

    just add a hidden field of counter, when you submit, get value of counter then loop from 1 to value of counter and request optionname + counter. jquery should be used to set the value of counter.

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

Sidebar

Related Questions

I need to create a random number of dropdownlists in my view, based on
i am using following code to make an httpPost call but it is returning
This MVC tutorial suggests to make dropdownlists like so: // // POST: /StoreManager/Create [HttpPost]
I'm using jQuery to make an Ajax call using an Http Post in ASP.NET
I make a lot of web applications and from time to time I need
So I need to make a a cross domain request where the response is
I need help with figuring out how to get hold of the redirect after
I use Apache's DefaultHttpClient() with the execute(HttpPost post) method to make a http POST.
I need to make POST request to REST web-service with header params and form
I need to send a HTTPPost with body gzipped, the server accepts non gzipped

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.