Learning ASP. NET 4.5 mvc4.0 with me (1)

Source: Internet
Author: User

The above project uses ASP. net4.0 mvc3.0, when recruiting, I found that many people have heard of MVC, but it has never been used. I am only a bit confused about MVC. Recently I want to give a systematic explanation to the team members, let everyone learn about ASP. net mvc3.0. However, because Windows 8 and vs11 were installed two days ago, I wrote some articles about ASP. NET 4.5 and mvc4.0. By the way, I would like to review mvc3.0. Some of the items involved here are mvc3.0, and some will be compared with mvc4.0, because I have just been in touch with ASP. NET mvc4.0 and do not know much about its improvement. If it is incorrect, please criticize and correct it. At the same time, I hope everyone can make common progress. The most important thing is that my team members can learn more about ASP. NET mvc3.0 or mvc4.0 development.

 

First, declare the relevant series (for the time being, plan to write the series, hopefully it will be more completeArticle(* ^__ ^ *) Some content may be translated or excerpted from the Internet. If you infringe your copyright, contact me, I will rewrite or correct it as soon as possible. Let's take a look at the topic. First of all, we need to build an MVC project. Open vs11, you can start from Win8 on the page of MetroProgramYou can also search for it in your folder, But I have fixed it in the taskbar.

 

There is no difference. Just like vs2010, you can select MVC application. Compared with ASP. NET mvc3.0, there are several more projects: webapi, mobile application, and single page application. If you select Internet application for other projects, it may be slow to create a project for the first time because nuget is released, patience for the first time.

 

In vs11, the default debugging server uses IIS Express, which is much easier to use than the virtual one, because the speed is much faster, just in my own opinion, I don't know if you have the same feelings? Let's first take a look at the allowable conditions. When using the debug button, we can see that there are many more options under the debug button? Including all browsers and page inspector installed on your machine (a very useful debugging tool ).

 

Here we choose to use the page debugging tool. We need to activate it for the first time, that is, set the web. the configuration node of config, as shown in. The specific modification is to enable the web when activating the design. config.

 

As shown in the running result, the figure also shows the content related to each window, so that we can understand the page debugging mechanism and related functions, and understand that the screen size is good, if there are conditions, you can use two screens, which are easy to set in Win8. The "device" on the right has the option for the second screen.

 

Compared with ASP. NET mvc3.0, there have been many changes in 4.0. First, jquery and some other script versions have been upgraded, and of course Microsoft's own Ajax library has been removed. It is estimated that there are too few people to use. There is an additional "Contact Us" on the page, and nothing else has changed. HoweverCodeThere are many changes that are worth studying. First, let's open the code of Global. asax and we can see that there have been many changes.1 UsingSystem;

2 Using System. Collections. Generic;
3 Using System. configuration;
4 Using System. Data. entity;
5 Using System. Data. entity. Infrastructure;
6 Using System. LINQ;
7 Using System. Web;
8 Using System. Web. HTTP;
9 Using System. Web. MVC;
10 Using System. Web. optimization;
11 Using System. Web. Routing;
12
13 Namespace Mvc4.website
14 {
15 // Note: For instructions on enabling IIS6 or iis7 Classic mode,
16 // Visit Http://go.microsoft.com /? Linkid = 9394801
17
18 Public Class Mvcapplication: system. Web. httpapplication
19 {
20 Public Static Void Registerglobalfilters (globalfiltercollection filters)
21 {
22 Filters. Add ( New Handleerrorattribute ());
23 }
24
25 Public Static Void Registerroutes (routecollection routes)
26 {
27 Routes. ignoreroute ( " {Resource}. axd/{* pathinfo} " );
28
29 Routes. maphttproute (
30 Name: " Defaapi API " ,
31 Routetemplate: " API/{controller}/{ID} " ,
32 Defaults: New {Id = routeparameter. optional}
33 );
34
35 Routes. maproute (
36 Name: " Default " ,
37 URL: " {Controller}/{action}/{ID} " ,
38 Defaults: New {Controller = " Home " , Action = " Index " , Id = urlparameter. optional}
39 );
40 }
41
42 Protected Void Application_start ()
43 {
44 Arearegistration. registerallareas ();
45
46 // Use localdb for Entity Framework by default
47 Database. defaultconnectionfactory = New Sqlconnectionfactory ( " Data Source = (localdb) \ v11.0; Integrated Security = true; multipleactiveresultsets = true " );
48
49 Registerglobalfilters (globalfilters. filters );
50 Registerroutes (routetable. routes );
51
52 Bundletable. Bundles. registertemplatebundles ();
53 }
54 }
55 }

Here, the routing configuration of webapi nodes is added, which is used by webapi. One option enumeration is also different. We will learn about webapi content separately in the following sections, I will not talk about it here. In the application startup method, the Entity Framework Database Configuration instance is configured by default. This framework is not used in our project, because I have heard that the performance is not good. In addition, his programming habits are not suitable for me, so he is useless. If someone has used him to develop enterprise websites or software, they can exchange ideas and give them some experience.The last difference is the bundletable Code. According to my understanding, this code is mainly used for webapi optimization and should also be a new feature of mvc4.0, the main reason is that webapi removes unnecessary white spaces and characters while transmitting JavaScript and CSS over HTTP and improves performance with some optimal optimizations. It can be seen from the name of the assembly where it is located that it belongs to performance optimization and is available only when mvc4.0 is used.

 

When you open the layout page, we will find that the URL path conversion also changes using system. web. optimization. bundletable. bundles. instead of using the URL. content, of course, can also be used, maybe the performance will be optimized, this needs to be further confirmed. If we modify the page content involved in page Inspector, it will prompt whether to refresh the traffic page, and click it to display it directly, as shown in.

 

Another major improvement is that HTML5 has been used for layout. Generally, people who use Firefox and chrome will keep pace with the times. However, the number of IE6 users is also a huge amount of data, therefore, we hope that "modernizr" can help us use the power of HTML5. This article mainly refers to an understanding of ASP. NET mvc4.0 and vs11. Although the vs11 interface is ugly, its functions are indeed very advanced.

Related Article

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.