我有以下观点。这是我的观点的全部代码
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div>
<table>
<tr>
<td>
<select id="clientDDL">
</select>
<% Html.DropDownList("clientDDL",
new SelectList((IEnumerable)ViewData["Clients"], "Code", "Name")); %>
</td>
</tr>
</table>
</div>
</asp:Content>
我使用模型中的下一个 ViewData:
public static List<lookup> GetClients()
{
using (ModelDataContext data = new ModelDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
List<lookup> retVal = new List<lookup>();
List<Client> lClient = data.Clients.Where(a => a.IsActive == true).ToList();
lClient = lClient.OrderBy(o => o.ClientName).ToList();
foreach (Client item in lClient)
{
retVal.Add(new lookup() { Code = item.ClientID.ToString(), Name = item.ClientName, });
}
return retVal;
}
}
这是我的控制器:
public ActionResult ProcedureFilter()
{
ViewData["Clients"] = WorkflowModels.GetClients();
return View();
}
我错过了什么?我的 DropDownList 仍然是空的。也许我必须提供一些参考?请有任何建议。
更新:问题是';' 在 <%= %> 部分的末尾。作品代码:
<%= Html.DropDownList("clientDDL",
new SelectList((IEnumerable)ViewData["Clients"], "Code", "Name")) %>