我有一个SQL Server表,它看起来像这样:
Month | Percentage
1 5
2 6
3 8
4 10
我想在Blazor视图中显示这张表,但它看起来像:
Month 1 2 3 4
Percentage 5 6 8 10
我想知道这样的事情是否可能,因为在之前我从未在c#中使用过枢轴
正如Henk在评论中所说,您可以使用2个foreach循环
<table class="table-bordered">
<tr>
<td>
Month
</td>
@foreach (var val in YourSqlTableModelList)
{
<td>@val.Month</td>
}
</tr>
<tr>
<td>
Percentage
</td>
@foreach (var val in YourSqlTableModelList)
{
<td>@val.Percentage</td>
}
</tr>
</table>
@code{
protected List<YourSqlTableModel> YourSqlTableModelList { get; set;}
public class YourSqlTableModel
{
public string Month { get; set;}
public string Percentage { get; set;}
}
//call the method to get the values from the sql server table
}
这是一个展示如何透视表的网站,如果您需要的话:(https://www.codeproject.com/Articles/22008/C-Pivot-Table