要在 ascx 视图上使用的对象列表,其中继承数据已加载 MVC
我有一个对象列表从数据库加载到下拉列表。模型将数据加载到控制器。 aspx 视图包括一个ascx 视图。 ascx 视图已经从另一个项目继承了数据。我无法在 ascx 页面中设置列表对象。这可以做到吗?
模型
...
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对象。帮助!!!
I have an object list being loded from a database to a drop down list. The Model loads the data to the Controller. The aspx view includes an ascx view. The ascx view already inherits data from another Project. I cannot set my List object in the ascx page. Can this be done?
Model
...
string List = dr["example"].ToString().Trim();
int indicator = dr["ex"].ToString().Trim();
LossCauseList.Add(new LossCauses(indicator, List));
...
Controller
LossCauses test = new LossCauses();
test.GetLossCauses(LossType);
TempData["Select"] = test.LossCauseList;
return View(myData);
Partial View
...
<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>
...
Partial view's List should be an actual LossCauses object. HELP!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将部分视图更改为
Change the partial view to