c# - Web 应用程序表
问题描述
我正在开发一个 Web 应用程序项目,在我的模型中我有两个列表:
public IEnumerable<Employee> EmployeeList { get; set; }
public List<int> AnotherInfo { get; set; }
在我的视图模型中,我将 Employee 列表中的项目显示为表格:
@foreach (var employee in Model.EmployeeList)
{
<tr>
<td>@employee.Names</td>
<td>@employee.Age</td>
<td>@@employee.Address</td>
</tr>
}
结果,我有一个包含 3 列的表:姓名、年龄和地址。
现在我想要第四列显示第二个列表:AnotherInfo
有什么办法可以使第四列与其他列位于同一行?
解决方案
您可以尝试解析EmployeeList
为列表并使用循环进行for
循环,如下所示:
public List<Employee> EmployeeList { get; set; }
public List<int> AnotherInfo { get; set; }
@for (var index = 0; index < EmployeeList.Count; index++)
{
var employee = EmployeeList[index];
var info = AnotherInfo[index];
<tr>
<td>@employee.Names</td>
<td>@employee.Age</td>
<td>@employee.Address</td>
<td>@info</td>
</tr>
}
更新:
如果你不能改变 的类型EmployeeList
,你仍然可以根据它制作一个副本列表:
List<Employee> list = EmployeeList.ToList();
// or
// var list = EmployeeList.ToList();
然后,您尝试上面的解决方案。
推荐阅读
- markdown - 如何使用 gist markdown 嵌入 Google-CSE?
- windows - 用于断点和延迟的无人值守 WinDbg 脚本
- android - 如何读取android studio中不可用的手机的mac地址
- woocommerce - 简码显示 WooCommerce 产品变化下拉列表
- matlab - 从 MATLAB 中的字符数组生成所有可能的子集
- java - 如果对象满足某些条件,则从 Map 中删除条目
- node.js - 如何查询对象中键的值?
- sql - 通过包含零将多个计数与组组合
- c++ - c++ - 如何在c ++ UE4中修复错误“函数式宏调用'TEXT'的参数过多”
- c++ - 面对 C++ 错误 ==> clang: error: 链接器命令失败,退出代码为 1(使用 -v 查看调用)