Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 9: Creating Web Applications with ASP.NET MVC 251
View, and the Controller, including relationships. There are variations of the relationship
between Model, View, and Controller, so rather than a theoretically correct depiction of all
scenarios, Figure 9-1 is a simplification that should help you get started.
In Figure 9-1, you can see that the Controller references both the V
iew and the Model.
This makes sense when you consider that the Controller is managing the operation of the
application. The Controller executes in response to a user request. Since the Controller
is also responsible for coordinating activity between the Model and the V
iew, you can
see the relationship in Figure 9-1 where the Controller references the Model. The
View
references the Model because the View must bind data to the user interface and needs to
know what data is available. The Model does not reference the View or the Controller. The
Model is an object that holds data and any other members that help manage that data, such
as methods for performing validation.
A typical sequence of operations for an ASP.NET MVC operation starts with a request
to a Controller. The Controller will perform the actions requested, working with the Model.
The Controller will then give the Model to a View and run the View. The View will display
Model data and interact with the user for any screen operations. Based on user interaction
with the View, more requests will be made to a Controller to repeat this process. The rest
of this chapter shows you how to write the code to make this process work, starting with
creating a new ASP.NET MVC project.
Starting an ASP.NET MVC Project
Just as with any other project in VS, you open the New Project window by selecting
File | New | Project. Then create an ASP.NET MVC 2 Web Application project named
MyShopCS (MyShopVB for VB). VS will ask if you want to create a test project, and
Figure 9-1 The Model View Controller pattern
ModelView
Controller
Request