【发布时间】:2010-03-29 18:45:53
【问题描述】:
我有一个从数据库加载到下拉列表的对象列表。模型将数据加载到控制器。 aspx 视图包括一个 ascx 视图。 ascx 视图已经从另一个项目继承数据。我无法在 ascx 页面中设置我的 List 对象。这个可以吗?
型号
...
string List = dr["example"].ToString().Trim();
int indicator = dr["ex"].ToString().Trim();
LossCauseList.Add(new LossCauses(indicator, List));
...
控制器
LossCauses test = new LossCauses();
test.GetLossCauses(LossType);
TempData["Select"] = test.LossCauseList;
return View(myData);
局部视图
...
<select id="SelectedProperty">
<% List<string> selectProperty = new List<string>();
selectProperty = TempData["Select"] as List<string>;
foreach(var item in selectProperty) { %>
<option><%=item.ToString() %></option>
<% } %>
</select>
...
部分视图的列表应该是一个实际的 LossCauses 对象。救命!!!
【问题讨论】:
标签: c# html asp.net-mvc asp.net ascx