Friday, June 29, 2012

Create MVC Website

Before you can do anything with ASP.NET MVC, you have to create a website to work with. Fortunately, it is easy to do.

Step 1: Find the Project Type in Visual Studio

Open up Visual Studio 2008. Go to File > New > Project in the menu. You will get a dialog much like the following image. Pick the "Web" category.
Picture of the add project dialog.
You can, of course call the project whatever you want and put it wherever you want. Next step.

Step 2: Create a Test Project

This is not necessary but is highly recommended. After all, automating tests is a useful activity.
Picture of the add test project dialog.

As you can see, there is a dropdown for selecting test frameworks other than that which comes with Visual Studio. If you have another test framework that you use, feel free to use it.

Take a Look at What You Get

You now have an MVC project. So now let's take a look at what you have.
Picture of solution explorer for a newly created project.
A few things here. The content folder is the place to put images and css. Putting such things there is not necessary. That is simply the default recommendation. The controllers folder is where you put your controller classes. If you are wondering what that is, well, that will be defined soon enough. This is actually one of the two core pieces of what ASP.NET MVC really is. The models folder is potentially a place to put any "business logic" classes you want to use but it can, frankly, just be deleted. Unless you want to put code there, do not feel constrained to do so. The scripts folder is for javascript files. The views folder is the other super-important core pieces of the ASP.NET MVC framework, and contains your Html files.
In the next section we will discuss the pattern around which ASP.NET MVC is built, the Model-View-Controller pattern. After that we will come back to solution explorer and see how that pattern is applied to the project file, and how they expect code to be written using this framework.

No comments:

Post a Comment