我有一个从数据库加载到下拉列表的对象列表。模型将数据加载到控制器。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>
...
部分视图的 List 应该是一个实际的 LossCauses 对象。帮助!!!