Reputation: 1067
I'm new to ASP.NET MVC, so please bear with me.
I always thought the idea of MVC (in any language) was that the view knows nothing about the model and vice versa, and that the controller is the glue that holds everything together.
Now when (in Visual Studio 2013 / MVC 5) I add a new controller via Add --> New Scaffolded Item, the generated view contains as first line
@model IEnumerable<MyModelClass>
I understand that is nice to have IntelliSense working when writing a view, but shouldn't the view be agnostic / completely oblivious to the model?
Upvotes: 0
Views: 197
Reputation: 18155
It's the model (or viewmodel if you prefer) that is the glue that holds everything together.
The view has to know about the model/viewmodel, otherwise the designer of the view could put any fields they want on the form and submit them to the controller without knowing whether or not the controller can accept those values.
Bottom line, the model/viewmodel is the contract that both the controller and the view understand and use to communicate between themselves.
Upvotes: 6