views:

48

answers:

1

I'm creating an MVC2 site which is a new, refreshed version of a site built in Web Forms.

Due to the nature of some of the features and the a database of statistics and their structure there is no one-size-fits-all way to display some of the information needed to be displayed.

Thus, despite following MVC principles elsewhere, in one feature a new partial view needs to be coded for each instance. This means that a View User Control has been made and I've stuck a "code behind" file into it, and extended the ViewUserControl class... much like the Web Forms way of doing it.

Is this really wrong, or can anyone suggest a better way of feeding only vaguely structured data to the partial view without having to put it all in there?

Thanks!

A: 

Daniel,

with out knowing the full details and based on my understanding of the question, i'd say 'yes'. basically, if the data is only 'vaguely' structured, you should examine the commonalities and create an interface that all those shared views would use. that way, you get the benefit of reuse without having to code a monolithic and potentially ever-growing code behind class.

The advantages of this may not be apparent until you've hit a critical mass of repeats (which could a few versions down the line).

if you're comfortable with this, it'll also make for better unit testing as well - this could be in itself a deal 'maker'.

jim