当我运行此时,下拉列表根本不会显示。它出现在早些时候;我不确定我改变了什么让它变得不起作用。只显示提交按钮。
<div class="container">
<h1>Enter Wellness Activity
</h1>
Select Activity Type:<br />
@{
List<Activity> acts = ViewBag.Activities;
var selectItems = new SelectList(acts, "code", "shortTitle");
ViewBag.selectItems = selectItems;
}
<div class="input">
@{
Html.BeginForm("ActivitySelected", "Home");
Html.DropDownList("selectItems");
<br />
<button name="submit" value="Submit">Submit</button>
// Html.EndForm();
}
</div>
</div>
答案 0 :(得分:1)
您需要对此代码进行三项更改才能使其生效。更改DropDownList,更改表单,然后更改提交按钮,如下所示:
<div class="input">
@using(Html.BeginForm("ActivitySelected", "Home"))
{
@Html.DropDownList("selectItems", ViewBag.selectItems)
<br />
<input type="submit" name="submit" value="Submit" />
}
</div>
顺便说一句,不要在View中将SelectList分配给ViewBag.selectItems
,而是在Controller中执行。
答案 1 :(得分:0)
尝试Html.DropDownList(&#34; selectItems&#34;,selectItems);
请参阅此重载方法:http://msdn.microsoft.com/en-us/library/gg548304(v=vs.111).aspx
答案 2 :(得分:0)
将项目设置为ViewBag.selectItems
后,您没有对它们执行任何操作。
尝试将它们传递到下拉列表中:
Html.DropDownList("selectItems", ViewBag.selectItems);