我为传入视图的字符串列表中的每个项目动态生成 DropDownList,然后为一些标准选项生成下拉列表,下拉列表名称为字母“drp”+通过视图数据传入视图的字符串项目。我遇到的问题是我无法弄清楚如何访问视图中 HttpPost 中的单个下拉列表,因为项目的名称和数量各不相同。
这是我的视图的获取代码:
public ActionResult ModMapping()
{
ViewData["mods"] = TempData["mods"];
return View();
}
这是我的视图生成:
<% 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>