在asp.net mvc中我如何使用带有选定值和onchange事件的htmlDropdownlist?

时间:2010-07-13 05:06:08

标签: asp.net asp.net-mvc

如何使用选定的值加载下拉列表还有一个onchange事件?

List<SelectListItem> environments = new List<SelectListItem>();

environments.Add(new SelectListItem { Text = "Development", Value = "DEV"});
environments.Add(new SelectListItem { Text = "Staging", Value = "STA" });
environments.Add(new SelectListItem { Text = "SNL", Value = "SNL"});
environments.Add(new SelectListItem { Text = "Production", Value = "PROD" });

 ViewData["Environments"] = new SelectList(environments, "Value", "Text", environment);

<p>Select a Deploy to: <%=Html.DropDownList("Environments", (SelectList)ViewData["Environments"], new { onchange = "this.form.action='DeployToChanged';this.form.submit()" })%></p>

1 个答案:

答案 0 :(得分:0)

你在谈论在页面加载时预先选择一个吗?

new SelectListItem { Text = "..", Value = "..", Selected=true}