Solution design

368

1. Customize template

2. Architecture design

3. Design a view that requires data from multiple Models

There are three possible approaches to solving this problem. One is to define a new model in the Modelfolder of your
MVC project that is a composite that will contain all the data sources needed for your view. Another approach is to
create several partial views, each with its own model, and then mash them all together in one super-view.
The advantage of the first approach is that it is very customable to your use case and you can accommodate for
unique data relationships that may only appear in your view. The downside is that you will not be able to reuse the
model and may end up repeating code such as data annotations in multiple places. The second approach would be
more attractive if you foresee using the partial views in several places in your application.
Rather than sending the data to the view via server-side code, the third approach is to make the data available
via a Web API and then have script blocks on the page call the services and render the user interface client-side. This
approach works well if you are expecting to support mobile devices and Windows Store applications in addition to
your web application. It also provides an additional benefit of gained scalability since you are pushing the rendering
logic to the client. The downside of this approach is that it can result in a large amount of difficult-to-maintain-andtest client code. This problem can be partially mitigated with the use of client-side MVC Frameworks and unit
test libraries.

4. Using Partial Views to Construct a Composite User Interface

5. Creating a Model Using Entity Framework Database First