tags:

views:

30

answers:

1

I've got a table of items, each with its own <select>. How do I bind these to the parameters of a controller method?

Ideally, I'd like an array containing (for each row in the table) the value of the selected option.

How do I do this? My google-fu is weak today.

+1  A: 

All your <select>s must have the same name plus [n], where n is zero based. Try this:

<% var i = 0; %>
<% foreach(var row in Model.Rows) { %>
<tr>
    <td>
        <%= Html.DropDownList(String.Format("options[{0}]", i++), row.Options as IEnumerable<SelectListItem>) %>
    </td>
</tr>
<% } %>

and your POST action could look like this:

public ActionResult YourAction(string[] options)
{
    ...
}
eu-ge-ne