1

I'm new to MVC and I wanted to check with those who might have some experience here.

If I understand correctly, the model in MVC is used to encapsulate view logic, behaviour that you want to occur at the view level. For the same kind of data (eg. EF model, WCF DataContract) you may actually have 2 or 3 different models to support editing and/or presentation of that data.

I was worried about DRY, but I'm now thinking that it's correct that the WCF contract will be "translated" into the model objects for the given view. Effectively the models would have a constructor from a WCF DataContract and they would have a method to produce the DataContract from the data in the model?

Advice?

Spence
  • 28,526
  • 15
  • 68
  • 103

1 Answers1

0

"the model in MVC is used to encapsulate view logic, behaviour that you want to occur at the view level" - I would disagree with this. The Model should be the representation of your business concepts. The View is concerned with presentation and renders your Model (e.g. as an HTML page).

The form of your model may be domain objects with behaviours or, if this is encapsulated by another service, the data contracts which that service returns. The view itself should be largely agnostic to what 'type' of model is being passed to it. It should only care that the relevant data it requires to produce the rendering is present.

Note that MVC also has the notion of a ViewModel, which is a representation of items from the model specifically designed to contain all the information required by a specific View for rendering, see my answer here for some more on that.

Community
  • 1
  • 1
Adam Ralph
  • 29,453
  • 4
  • 60
  • 67