views:

31

answers:

1

Hi there,

I am just figuring out best practice with MVC now I have a project where we have chosen to use it in anger.

My question is.

If creating a list view which is bound to an IEnumerable is this bad practise?

Would it be better to seperate the code generated by the WCF Service reference into a datastructure which essentially holds the same data but abstracts further from the service, meaning that the UI is totally unaware of the service implementation beneath.

or do people just bind to the proxy object types and have done with it ?

My personal feeling is to create an abstraction by creating a model and placing the Collection in that and referring to the collection in the UI code from the model.

but this seems to violate the DRY principle with respect to proxies.

+1  A: 

Well, the best practice is to use a View Model which is populated from the Model. In many cases they could be the same because the view shows all the properties returned by the service, but another view could show only a subset of them. That's why having a view model is considered a good practice. This view model can also contain some calculated properties that are specific to the view. To further simplify the mapping between those objects you could use AutoMapper. There's also a nice article you may take a look at explaining the concept of view models.

Darin Dimitrov
thank you, I rather thought this to be the case as I have been used to MVC in other areas and was using a model with data and not using the proxies directly, I had quickly knocked up a number of screens which used proxy classes, I thought this was a bit nasty and your answer confirms this. Thanks for the article by the way, very informative.
krystan honour