阅读您的问题后,听起来您希望下拉列表为同一页面的较低部分提供值。
首先,您需要将 DropDownList 放在表单结构中,如下所示:
<% using (Html.BeginForm("ProcessValue", "ThisPage")) { %>
<%= Html.DropDownList("DropID", Range(0, 10).Select(a=>new SelectListItem { Text = x, Value = x }) %>
<input type=submit value="Submit" />
<% } %>
您需要提前设置一些东西:
- 您必须有一个提交按钮或类似的构造,才能检索 DropID 变量的值。
- 您需要设置一个控制器方法来处理值的处理,然后使用页面的 ViewData 中的选定值重定向回原始页面。
- 最后,您需要设置视图,以便只有在 DropID 变量中有有效值时才会显示后处理部分。
It's not as simple as just placing a DropDownList in a view and then using that value later on in the page. You have to get the controller involved to manage the data transport and you have to set up the single view to handle multiple states (ie. before the value is selected and after the selection takes place).