I dynamically generate the DropDownList for each item in List of string I pass into my view, and then generate a dropdownlist for some standard options with the dropdownlist name being the letters "drp" + the String item that was passed in view via viewdata. The problem I am running into is that I can't figure out how to access the individual Dropdown List in the HttpPost in the view because the names and number of items vary.
Here is my Get Code for my View :
public ActionResult ModMapping()
{
ViewData["mods"] = TempData["mods"];
return View();
}
Here is my View Generation:
<% using (Html.BeginForm()) { %>
<h2>Modifier Needing Mapping</h2>
<p>Please Choose for each modifier listed below what type of fee it is. There is an ingore option if it is not a gloabl fee modifier, professional fee modifier, or technical fee modifier.</p>
<table>
<tr>
<th>Modifier</th>
<th>Mapping Options</th>
</tr>
<% int i;
i=0;
var modsList = ViewData["mods"] as List<String>;%>
<% foreach (String item in modsList) { %>
<% i++; %>
<tr>
<td>
<%: Html.Label("lbl" + item, item) %>
</td>
<td>
<%: Html.DropDownList("drp" + item, new SelectList(
new List<Object>{
new { value = "NotSelected" , text = "<-- Select Modifier Type -->"},
new { value = "Global" , text = "Global Fee" },
new { value = "Professional" , text = "Professional Fee"},
new { value = "Technical", text = "Technical Fee"},
new { value = "Ingore", text="Ingore This Modifier"}
},
"value",
"text",
"NotSelected")) %>
</td>
</tr>
<% } %>
</table>
<input type="submit" value="Done" />
<% } %></code>