Is it "tearing" MVC to get model information in a view?

I am new to MVC and I have a question regarding my view.

I have a strongly typed view:

@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>

Does this violate the MVC rules for referencing parts of the model in my opinion, such as

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

or

(cell.State == CellularAutomata.Models.State.On)

If this is not true, what is the best way to fix it?

+3
source share
1 answer

Not at all, as your view is strongly typed against your model. If your view was an agnostic of the model, that would be a problem, but since this view is for D1CellularAutomata, you have the corresponding D1CellularAutomata links in your view.

+4
source

Source: https://habr.com/ru/post/1793890/


All Articles