Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 是';中断';MVC是否在视图中包含有关模型的信息?_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 是';中断';MVC是否在视图中包含有关模型的信息?

Asp.net mvc 3 是';中断';MVC是否在视图中包含有关模型的信息?,asp.net-mvc-3,Asp.net Mvc 3,我是MVC新手,我对自己的观点有疑问 我有一个强类型视图: @model CellularAutomata.Models.D1CellularAutomata @{ ViewBag.Title = "View"; } <h2>View</h2> <table> @foreach (CellularAutomata.Models.Grid grid in Model.GridHistory){ <tr> @fore

我是MVC新手,我对自己的观点有疑问

我有一个强类型视图:

@model CellularAutomata.Models.D1CellularAutomata
@{
    ViewBag.Title = "View";
}
<h2>View</h2>

<table>
@foreach (CellularAutomata.Models.Grid grid in Model.GridHistory){ 
    <tr>
        @foreach (CellularAutomata.Models.Cell cell in grid.Cells[0]){
            if (cell.State == CellularAutomata.Models.State.On){
                <td>X</td>
            }
            if (cell.State == CellularAutomata.Models.State.Off){
                <td>O</td>
            }
        }
    </tr>
}
</table>


如果这是错误的,那么最好的解决方法是什么?

一点也不,因为您的视图是针对您的模型的强类型视图。如果您的视图是模型不可知的,那么这将是一个问题,但由于这是D1CellularAutomata的视图,因此在视图中具有D1CellularAutomata特定的引用是合适的

(CellularAutomata.Models.Cell cell in grid.Cells[0])
(cell.State == CellularAutomata.Models.State.On)