C# Web应用程序表
我正在从事一个Web应用程序项目,在我的模型中,我有两个列表:C# Web应用程序表,c#,html,razor-pages,C#,Html,Razor Pages,我正在从事一个Web应用程序项目,在我的模型中,我有两个列表: public IEnumerable<Employee> EmployeeList { get; set; } public List<int> AnotherInfo { get; set; } public IEnumerable EmployeeList{get;set;} 公共列表另一个信息{get;set;} 在我的视图模型中,我将员工列表中的项目显示为一个表: @foreach (var
public IEnumerable<Employee> EmployeeList { get; set; }
public List<int> AnotherInfo { get; set; }
public IEnumerable EmployeeList{get;set;}
公共列表另一个信息{get;set;}
在我的视图模型中,我将员工列表中的项目显示为一个表:
@foreach (var employee in Model.EmployeeList)
{
<tr>
<td>@employee.Names</td>
<td>@employee.Age</td>
<td>@@employee.Address</td>
</tr>
}
@foreach(Model.EmployeeList中的var employee)
{
@员工姓名
@雇员年龄
@@员工地址
}
因此,我有一个包含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>
}
然后,尝试上面的解决方案。另一个信息中的数据与员工的关系如何?您想在列中显示整个列表还是仅显示列表中的一个值?。。。是否为标题添加
,为数据添加
?您的问题是什么?这假设两个集合的大小相同。可能只需要澄清一下情况是否确实如此。@reti是的,我想他们的大小相同。是的,他们的大小相同,这看起来像我想要的,但问题是EmployeeList的类型是IEnumerable,所以我无法通过index@gameloverr2call.toList()然后将结果列表传递给页面模型。
List<Employee> list = EmployeeList.ToList();
// or
// var list = EmployeeList.ToList();