I have a page in my MVC3 web app that has a table with 20 or so rows in it. Each row has a dropdown in it (the same drop down for each row).
I want to be able to pass all of the dropdown SelectedValues back to my controller in one array.
I have done something similar where I had a bunch of checkboxes all named the same thing and then I was able to put int[] checkboxname in the controller signature. The same thing doesn't seem to work with dropdowns. It only ever passes 1 value back to the controller rather than an array of values.
Basically in my View, I have
Loop start
@Html.DropDownList("gridMultipliers", (SelectList)ViewBag.GridMultiplierList)
Loop End
Then in my controller signature, I have
public ActionResult MyMethod(int[] gridMultipliers){
//stuff here
}
I'm pretty sure you're going to have to do something more along these lines:
@Html.DropDownList("gridMultipliers" + i, (SelectList)ViewBag.GridMultiplierList)
where i
is the loop iteration. This should then get transformed into an array when it's posted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.