如何将二维数组值从 C# 显示到视图?
How do I display a 2D-array value from C# to a View?
我在 C# 中有一个二维数组
public class DBResult
{
public string[,] dbDataArray = new string[100, 100];
}
如何使用 Razor 在视图中显示单元格的值?
我这样做
@Html.DisplayFor(model => model.dbDataArray[0,0])
但是我收到以下错误
"Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."
@model string[,]
<table>
@for (int row = 0; row < Model.GetUpperBound(0); row++)
{
<tr>
@for (int column = 0; column < Model.GetUpperBound(1); column++)
{
<td>@Model[row, column]</td>
}
</tr>
}
</table>
我在 C# 中有一个二维数组
public class DBResult
{
public string[,] dbDataArray = new string[100, 100];
}
如何使用 Razor 在视图中显示单元格的值?
我这样做
@Html.DisplayFor(model => model.dbDataArray[0,0])
但是我收到以下错误 "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."
@model string[,]
<table>
@for (int row = 0; row < Model.GetUpperBound(0); row++)
{
<tr>
@for (int column = 0; column < Model.GetUpperBound(1); column++)
{
<td>@Model[row, column]</td>
}
</tr>
}
</table>