如何使用选定的值加载下拉列表还有一个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>
答案 0 :(得分:0)
你在谈论在页面加载时预先选择一个吗?
new SelectListItem { Text = "..", Value = "..", Selected=true}