Visual Studio 2013 simplifies the process of creating ASP.NET MVC applications by providing various in-built templates. Visual Studio 2013 provides an MVC template that automatically creates an MVC application structure with the basic files to run the application. You will now learn how to create an ASP.NET MVC application in Visual Studio 2013.
1. Creating an ASP.NET MVC Project in Visual Studio 2013
To create an ASP.NET MVC application using Visual Studio 2013, you need to perform the following tasks:
1. Press the Windows+Qkey.
2. In the Searchbox that appears, start typing ‘Visual Studio 2013’. The Visual Studio 2013 icon appears under the Appssection.
3. Double-click the Visual Studio 2013icon. The Start Pageof Visual Studio 2013 appears.
4. Click File→New→Projects menu options in the menu bar of Visual Studio 2013.
5. In the New Projectdialog box, select Web under the Installed section and then, select the ASP.NET Web Application template.
6. Type ‘MVCDemo’ in the Nametext field.
7. Click Browse. The Project Location dialog box appears that allows you to specify the location where the application has to be created.
8. Click Select Folder. The New Project dialog box displays the specified location in the Location field. Figure 1.14 shows specifying a name and location for the application.
9. Click OK. The New ASP.NET Project – MVCDemodialog box appears
10. Select MVC under the Select a template section of the New ASP.NET Project – MVCDemo dialog box. Figure 1.15 shows selecting MVC under the Select a template section.
11. Click OK. Visual Studio 2013 displays the newly created application.
2. Structure of an ASP.NET MVC Project
When you use Visual Studio 2013 to create an ASP.NET MVC Web application, it automatically adds several files and folders to the project.
Figure shows the files and folders that Visual Studio 2013 creates automatically when you create an ASP.NET MVC application.
The top-level directory structure of an ASP.NET MVC application contains the following folders:
- Controllers: Contains the Controller classes that handle URL requests.
- Models: Contains the classes that represent and manipulate data and business objects.
- Views: Contains the UI template files that are responsible for rendering output, such as HTML.
- Scripts: This folder contains the JavaScript library files.
- Images: Contains the images that you need to use in your application.
- Content: Contains the CSS and other site content, other than scripts and images.
- Filters: Contains the filter code.
- App_Data: Contains data files that you need to read/write.
- App_Start: Contains the files containing configuration code that you can use features such as Routing, Bundling, and Web API.
3. Executing an ASP.NET MVC Project
To execute an application created in Visual Studio 2013, you need to click Debug→Start withoutdebugging from the menu bar. The browser will display the output of the default application.
Figure shows the output the default application created in Visual Studio 2013.
0 nhận xét:
Đăng nhận xét