[Translation] professional ASP. NET mvc3 (02)-Chapter 1: Getting Started (medium)

Source: Internet
Author: User
2. Create an ASP. NET mvc3 Application

To understand how mvc3 works, the best way is to create an application. Let's get started.

ASP. NET mvc3 Software requirements

Mvc3 can run in the following Windows client operating system:

    • Windows XP
    • Windows Vista
    • Windows 7

It can run on the following server operating systems:

    • Windows Server 2003
    • Windows Server 2008
    • Windows Server 2008 r2

The MVC 3 development tool can be installed on Visual Studio 2010 or visual web developer 2010 Express.

Install ASP. NET mvc3

After confirming that the basic software requirements are met, it is time to install ASP. NET mvc3 on your development machine and product machine. Fortunately, this is quite simple.

AndMVC2Parallel Installation

MVC 3 and MVC 2 can be installed in parallel, so you can install and start using mvc3 immediately. You can still create and update an existing MVC2 application as usual.Program.

InstallMvc3Development components

ASP. NET mvc3 developer tools support Visual Studio 2010 or visual web developer 2010 Express (free of charge ).

To install mvc3, you can use web platform Installer (http://www.microsoft.com/web/gallery/install.aspx? Appid = mvc3), or executable installation package (http://go.microsoft.com/fwlink? Linkid = 208140 ). I generally prefer to use web platform installer because it only downloads and Installs components that are not currently in use. The executable installation package can be run offline. It contains everything you need.

Server InstallationMVC 3

The installation package checks whether it runs on a machine that does not support the development environment, and only needs to install the server. If your server can access the network, webpi is a lightweight installation because there is no need to install any developer tools.

When mvc3 is installed on the server, the MVC runtime assembly is installed in the Global Assembly Cache (GAC), which means that all websites on the server can be used. Another way is to install MVC 3 on the server, but to include the required assembly in your application. This method is called binary deployment ), you can add the following assembly in the project reference and set it to copy local in the Visual Studio attribute ).

    • Microsoft. Web. Infrastructure
    • System. Web. helpers
    • System. Web. MVC
    • System. Web. Razor
    • System. Web. webpages
    • System. Web. webpages. Deployment
    • System. Web. webpages. Razor

For more information about the installation options, see Scott Guthrie's blog titled "running an ASP. net MVC 3 app on a web server that doesn' t have ASP. net MVC 3 installed, ", URL: http://weblogs.asp.net/scottgu/archive/2011/01/18/running-an-asp-net-mvc-3-app-on-a-web-server-that-doesn-t-have-asp-net-mvc-3-installed.aspx.

Create ASP. NET mvc3 Applications

After MVC 3 is installed, you will find that Visual Studio 2010 and Visual Web tracking both have some new options. These experiences are similar to those in the two ides. Because this book is an advanced series of tutorials, we will mainly focus on the Visual Studio development environment, visual Web Developer is mentioned only when there is a big difference between the two.

MVCMusic Store

We will use some examples based on the MVC music shop blog, the online address of these examples is: http://mvcmusicstore.codeplex.com, and contains a 150-page e-tutorial to explain the basis for building the mvc3 application. In this book we will be a little faster,However, if you need more information about introductory topics, they have a common starting point.(But it's nice to have a common base if you need more information on the introductory topics ).

Create an MVC project:

1. Select File> New> project, as shown in figure 1-2.

 

2. As shown in, in the template section on the left of the new project dialog box, select Visual C #-> web template column. A list of web application types is displayed in the middle column.

 

3. select ASP. NET mvc3 web application, name the application mvcmusicstore, and click OK.

 

New ASP. NET mvc3 dialog box

After creating a new mvc3 application, you will see a dialog box that contains some specific MVC options during project creation, as shown in figure 1-4. The option selected in the dialog box will generate some specific underlying structures for your application, including account management, view engine, and testing.

 

Application Template (Application templates)

First, select (1-4) from the two pre-installed project templates ).

    •  The Internet Application Template: The template contains the basic content of the MVC web application. After creation, you can run the template immediately and see some pages. This can be completed in just one minute. The template also contains some basic account management functions, which correspond to the ASP. NET membership system (discussed in chapter 7th ).

ASP. NET mvc3The update tool also addsIntranet application templateBut its account management function is notASP. NET membershipSystem, but aboutWindowsAccount.

    •  The empty teMplate:This template is basically empty. It also contains the basic architecture of folders, CSS, and MVC applications. Running the application created with an empty template directly will see the error message --You need to start development step by step from scratch(You Need to work just to get to square one ). In this case, why should we include this template? In fact, empty templates are designed to make it easier for experienced MVC developers to set and configure according to their own needs. We will take a brief look at the structure of the empty application in the second half of this chapter. For more information, see the MVC Music Store application, which is created using an empty template.

ViewEngine (View Engine)

In the new ASP. NET mvc3 project dialog box, the next option is the view engine drop-down box. The view engine provides different template languages for generating HTML tags in MVC projects. In versions earlier than mvc3, the only integration option of the view engine is aspx or web forms. This option is still available, as shown in figure 1-5.

 

Test (Testing)

If an internet or intranet application template is used, another option is available in the new ASP. NET mvc3 project dialog box. This part mainly deals with testing, as shown in figure 1-6.

If you do not select the check box for creating a test project, it means that your project does not contain any unit tests during creation, so there is no other need to do.

Recommendation: select the check box

I hope that you will become a habit of selecting the "Create unit test project" check box for each new project.

I'm not going to sell you the unit test faith-at least not yet. Throughout this book, we will talk about unit testing, especially chapter 1, which involves unit testing and testable models, but we are not going to force it into your throat (so that you can swallow it up ).

Therefore, I recommend that you select only this check box. You do not have to know the details or have an ALT. net or a certificate (meaning that you do not need to have any basic unit test knowledge ). In this book, we will involve some unit tests to get you started. The best way to get started with unit tests is to select this check box so that you can write some tests in the future without any settings.

After you select the create a unit test project check box (create a unit test project box), there are two additional options:

    • The first one is simple: you can modify the name of a unit test project at will;
    • The second option allows you to select a test framework, as shown in figure 1-7.

 

You may have noticed that there is only one test framework to choose from, and it seems unnecessary. There is only one drop-down box option because the unit test frame can be registered to this pair across the box, so if you have installed other unit test frameworks (such as xunit, nunit, mbunit, etc ), it will be displayed in the drop-down list.

Visual Studio unit test frameworkOnlyVisual StudioAvailable in professional or later versions. If you useVisual Studio 2010Standard Edition orVisual Web Developer 2010Enterprise Edition, You need to download and installASP. NET MVCOfNunit, mbunitOrXunitExtension package to see this dialog box.

 

Register the test framework for the unit test framework drop-down box

Have you ever wondered what is involved in registering a test framework for the new MVC project dialog box?

The process is described in detail on msdn (http://msdn.microsoft.com/en-us/library/dd381614.aspx ). There are two main steps:

1. Create and install a template project for a new MVC test project;

2. register the test project type by adding registry items under HKEY_CURRENT_USER \ Software \ Microsoft \ visualstudio \ 10.0 _ config \ mvc3 \ testprojecttemplates.

Check and confirm that the settings in the MVC 3 Application dialog box are consistent with those in Figure 1-8, and then click OK.

 

In this way, a solution containing two projects is created-one is a Web application and the other is a unit test project, as shown in figure 1-9.

 

 

 

Note: The reference book professional ASP. NET mvc3 is only for learning and communication. Do not use it for commercial purposes.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.