Does it 'break' MVC to have information about a model in a view?
I'm new to MVC and I have a question concerning my view.
I have a strongly typed view:
@model Cel开发者_JAVA百科lularAutomata.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>
Does it break the rules of MVC to reference parts of the model in my view, such as
(CellularAutomata.Models.Cell cell in grid.Cells[0])
or
(cell.State == CellularAutomata.Models.State.On)
If this is incorrect, what is the best way to go about fixing it?
Not at all, since your view is strongly typed against your model. If your view was model agnostic then it would be a problem, but as this is a view for D1CellularAutomata it is appropriate to have D1CellularAutomata specific references in your view.
精彩评论