1
我有一个城市的列表和国家的列表,他们都希望对视图(aspx)文件有。我想这样的事情,但它不工作:如何将多个模型分配到单个视图?
命名空间World.Controllers { 公共类WorldController:控制器{ 公众的ActionResult指数(){
List<Country> countryList = new List<Country>();
List<City> cityList = new List<City>();
this.ViewData["CountryList"] = countryList;
this.ViewData["CityList"] = cityList;
this.ViewData["Title"] = "World Contest!";
return this.View();
}
}
}
<table>
<% foreach (Country country in this.ViewData.Model as IEnumerable) { %>
<tr>
<td><%= country.Code %></td>
</tr>
<% } %>
</table>