2015-01-14 26 views
1

我在C#中的二維數組如何顯示從C#到視圖的2D數組值?

public class DBResult 
{ 
    public string[,] dbDataArray = new string[100, 100]; 
} 

如何使用剃刀視圖中顯示單元格的值?

我這樣做

@Html.DisplayFor(model => model.dbDataArray[0,0]) 

,但我得到了以下錯誤 「模板只能與現場訪問,訪問屬性,一維數組的索引,或單參數自定義索引表達式中使用。」

回答

1
@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> 
+0

非常感謝:)很棒! – Afz

相關問題