Skip to main content
6 of 12
added 167 characters in body
mishan
  • 211
  • 2
  • 11

I am not the greatest person to answer this as my knowledge is still lacking in many of the aspects, but I will try to give you a bit different perspective. So, when you receive a better answer from someone more knowledgeable you might want to listen to them :)

The MVC

The "MVC" in MVC means Model-View-Controller architecture.

It means that:

  1. The Controller does something
  2. During its work it produces a Model object
  3. This Model object is given to a View, which then uses the model for presentation

Nowhere in there is there a need for the model to do anything on its own.

The model is what we call the object used to pass information between the controller and the view.

ORM Models

Also, the Model you're showing is an ORM (object-relational mapping) model - it is not the same model that we're talking about in the MVC.

In your case, it's an Entity Framework model (class) describing a table (or a part of a table) in the database.

Dangers of using ORM model as MVC model

It can be used as a model (the object passed between the controller and the view) in MVC, but generally, I was always discouraged from doing so.

It is commonly used in simple or tutorial applications that way, as a proof of concept.

I was discouraged from doing so and am usually discouraging others unless the app is really simple or the risk of a malicious user is non-existent.

I am doing so because passing ORM models as MVC models introduces the potential for several problems like the developer forgetting to properly sanitize the model or the controller code working with it and just passing the resulting object to a database and allowing the potentially malicious user to wreak havoc.

It also forces you to separate your concerns and make proper models for the views, because you usually want to have some form of processed output in the fields you're showing, and doing complex processing in the view would introduce the logic which the controller is there to contain.

What about MVVM?

I also think you might be using the term MVC and mean MVVM (or MVB).

In MVVM, which means Model, View, ViewModel(Binder), the ViewModel(Binder) is responsible for notifying the view of its changes.

In MVVM (Edited, I had this wrong :) ):

  1. The Model is the background data (so, for example, the data represented by the collection of objects described in the ORM classes)

  2. The ViewModel(binder) uses the Model to fill itself (doing the combined job of the controller and the model)

  3. The ViewModel(binder) acts and notifies the View of the changes that happened inside itself and the View shows those changes

mishan
  • 211
  • 2
  • 11