I’ve seen several projects with a common problem in organizing Views in their MVC structure. The problem is that they end up with many Views slightly different from each other.
For instance, they usually need some grid lists of a single data set with various combination of data columns to display. There are also two common approaches for addressing this problem: creating a single but highly complex view file or creating several simple view files.
Is there a better approach out there ? Any best practices ?
If the problem is about rendering different set of columns then better approach is to send grid columns to single view while rendering. Problem is all about data and not static html then it’s fine to send data via controller/model.
Clearly, the form is already going down the rabbit hole. Now, imagine we would need to involve more parameters in the conditions with more complex views. It quickly turned to a nightmare which was neither readable nor maintainable. Using multiple forms wouldn’t make any better.
Further, if we render that form as part of other views in many parts of an application, it will become extremely difficult to develop and maintain.
It seems like object oriented design ends when code reaches HTML.
Could it be a better solution to apply Builder design pattern for creating a view builder in such situations?
I had this rather complex (or one may even say convoluted) conditional form. Started of with if/else as above, but finally arrived at breaking them down into two sections. All conditions were evaluated upfront and Boolean variables set first. The 2nd section used them to display the fields.