Reveal new features of mvc4

Source: Internet
Author: User

MVC 4 Overview

The mvc4 version is quite mature and can focus on some more advanced scenarios. Some advanced features include:

    • ASP. NET web API
    • Enhancements to default project templates (enhances the default Project template)
    • Mobile Project template using jquery mobile (use the mobile Project template of jquery mobile)
    • Display modes)
    • Task support for asynchronous controllers (tasks support asynchronous controllers)
    • Bundling and minifi cation (bundle and tiny)

ASP. NET web API

ASP. net mvc aims to create a website. The entire platform is clearly determined by the design, indicating the usage of the hypothesis: Responding to browser requests and returning HTML.

Mvc4 includes a better solution: ASP. NET web API (called web API). This framework provides the development style of ASP. net mvc and is designed for compiling HTTP services. This includes modifying some ASP. net mvc concepts to the HTTP service field and providing some new service-oriented functions.

Here are some web API functions similar to MVC that are only applicable to HTTP service domains:

    1. Routing: Web APIs of ASP. net use the same routing system to map URLs to Controller actions. It routes the background to the HTTP service's HTTP verb ing to the action according to the Convention, makeCodeIt is easier to read and encourage the following restful design services.
    2. Model binding and verification: As in the simplified process of MVC, ing input values (form fields, cookies, URL parameters, etc.), model values, and Web APIs automatically map HTTP request value models. The system of scalability and binding includes using MVC model binding based on the same attri-transport-based verification.
    3. Filters: MVC uses filters to allow adding actions through attributes. For example, adding the [authorize] attribute to the MVC action will disable anonymous access and automatically redirect to the logon page. Network APIS also support some lters standard MVC network connections (such as service optimization [authorize] attributes) and custom filters.
    4. (Scaffolding) scaffolding: Add a new web API controller using the same dialog box to add an MVC controller. You can choose to use "add controller diameter log to support fast, a web API controller based on the Entity Framework as the basic mode type.
    5. Simple Device testability: Just as MVC web API is built on the concept injection of dependencies, avoid using global states.

Network API also adds some new concepts and functions to clarify the development of HTTP Services:

    • HTTP web programming model: API development experience optimizes HTTP requests and responses. There is a strong HTTP object model, HTTP status code and header convenience.
    • The method is based on http: the MVC dispatch operation method is based on their name. HTTP.
    • Content negotiation: HTTP has been supporting system content negotiation for a long time. In browsers (and other HTTP clients), it indicates their preferred response format and the highest choice for server response, supported formats. This means that your controller can provide XML, JSON, and other formats (you can add your own) to respond to any client's favorite format. This allows you to add support for the new format without changing any controller code.
    • Code-based configuration: the configuration service may be complex. Unlike the detailed and complex configuration file method of WCF, Web APIs are fully configured by code.

Although ASP. NET Web APIs include mvc4, they can be used independently. In fact, it is not dependent on ASP. NET and can be self-managed, that is, the external hosting ASP. NET and IIS. This means that you can run Web APIs. NET ApplicationProgramIncluding Windows Services or even a simple console application.

Enhancements to default project templates

By default, the visual design of the template MVC project has basically remained unchanged through MVC 3. When you create a new MVC project and run it, you have a white square blue background, as shown in figure 1. In MVC, default templates for HTML and CSS have been completely redesigned. A new MVC application is shown in 1. In mvc4, default templates for HTML and CSS have been completely redesigned. A new MVC application appears 2.

Figure 1. Figure 2.

Your website should have its own custom design. This is good. At the bottom layer of HTML and CSS, mvc4 projects can all be marked with modern CSS, it can respond well to the increasing mobile browser rating.

Mobile Project template using jquery mobile

If you want to create a website, it will be considered as a mobile browser, you can use the new mobile Project template. This template pre-configures your website to use the popular jquery mobile library. It provides a style that looks good on mobile devices, as shown in figure 3 and 4. The Touch Optimization of jquery mobile supports Ajax navigation and supports enhancements of mobile devices row by row.

Figure 3. Figure 4.

Display modes

The display mode uses a convention-based method to allow the browser to send requests based on different points of view. By default, the view engine first looks for and uses the. Mobile. cshtml browser's user agent to indicate known mobile devices. In addition, you can also register your own custom device mode, which will be based on your own custom standards-all are just a code statement. For example, registering a winphone device mode will help end the view .. Winphone. cshtmlto Windows Phone, you will use the following code in your global. asax application_startmethod:

Displaymodeprovider. instance. modes. insert (0,NewDefaultdisplaymode ("Winphone") {Contextcondition= (Context =>Context. getoverriddenuseragent (). indexof ("Windows Phone OS", Stringcomparison. ordinalignorecase)> =0)});

Bundling and minification

ASP. NET 4 supports the same bundle and tiny frameworks including ASP. net4.5. The system reduces the number of single requests referenced to your website by combining several separate scripts. It also has "fewer" requirements, using technologies such as shortening variable names and removing spaces and comments. The operating principle of the system, as well as the CSS and CSS requests bundled into a single request, and the size of the compressed CSS request, in order to generate the minimum bytes, CSS selectors are disabled based on the same rules of advanced technologies such as semantic analysis.

Is a highly configurable bundling system that allows you to create custom bindings containing specific scripts and reference them with a single URL. You can see some examples reference the software package Internet templates listed by default in/app_start/bundleconfig. CS in a new MVC application.

You can delete files and reference your view code. This means that you can add or upgrade the script Library and the CSS network connection file with different file names, you do not need to update your view layout because reference scripts and CSS bundle instead of a single file. For example, the MVC Internet application temperature board contains a jquery package that does not depend on the version number:

 
Bundles. Add (New scriptbundle ("~ /Bundles/jquery "). Include ("~ /Scripts/jquery-{version}. js "));

This is the site layout referenced in the URL bundle (_ layout. cshtml), as follows:

 
@ Scripts. Render ("~ /Bundles/jquery")

Because these references do not depend on the jquery version number, the bundle and minor systems that update the jquery Library (either manually or through nuget) will be automatically picked up without any code changes.

Miscellaneous features (other features)

MVC includes a complete list of features that were not previously listed that are available in the release notes and can be seen in the http://www.asp.net/whitepapers/mvc4-release-notes.

    • The logic of configuration is moved to app_start: the new functions are good, but the additional logic uses the code configuration function to really start the global. asax application_start method that becomes messy. These configurations have been moved to the app_start directory of the static class.
    1. Authconfig. CS: Configure security settings, including website oauth logon.
    2. Bundleconfig. CS: used to register the used bundle and tiny bundle systems. Several bundles are added by default, including jquery and jquery verification, jqueryui, modernizr, and default CSS references.
    3. Filterconfig. CS: Undoubtedly, this is used to register a global MVC filter. The only network connection by default, the filter registers handleerrorattribute, but this is a great place to put
      Register other network connection filters.
    4. Routeconfig. CS: the configuration statement of the original MVC to configure the route.
    5. Webapiconfig. CS: used to register the web API route and configure any other webapi.
    • Empty MVC Project template: MVC contains an empty project template, because MVC2, but is it true empty, it still contains a CSS file, folder structure, and exceeds the JavaScript Network Connection file. This template has been renamed as "Basic" and a new Empty Project template due to a popular request. It is really empty.
    • Add a controller anywhere: Before that, add the Controller menu item in Visual Studio and right-click the Controller folder when only playback is displayed. However, the Controller folder used is purely organized. (MVC recognizes any class and implements the icontroller interface as the controller, regardless of its location in your application .) The mvc4 Visual Studio tool has been modified to display any of your MVC project folders in the "add controller" menu item. This allows you to organize your controllers, but you may think that they may be split into logical groups or separated MVC and web API controllers.

OK! The mvc4 features will be introduced here first. In the future, let's see if we can integrate some system things and learn from everyone! Thank you very much for your guidance and have learned a lot from soy sauce. Thank you very much! Hope you can give me more advice!ArticleIf there is something wrong or wrong with the description, please give us some advice! Looking forward! Why not have a holiday! Happy New Year! Looking forward to returning to your hometown .......

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.