ASP. net mvc 3 Preview

Source: Internet
Author: User

    The first preview version of ASP. net mvc 3 has been released, and this update has brought more improvements. Including views,Improvements in controller and JavaScript and Ajax.

    ASP. net mvc 3 is compatible with ASP. net mvc 2-that is to say, when MVC 3 is released, it makes it easy for you to update the MVC 2 project to MVC 3. The new functions of MVC 3 are based on MVC 1 and MVC 2, which means that the technology, knowledge, class libraries and books you have mastered can be directly used on MVC 3. MVC 3 only adds some new features-it does not eliminate existing features.

    ASP. net MVC 3 and ASP. net MVC 2 coexistence, you can install today's "preview 1" on the machine, without affecting your existing MVC 2 project (unless you explicitly specify the project to use MVC 3, otherwise, it will continue to use MVC 2 ). After "preview 1" is installed, some new ASP files are added in the "New Project" dialog box of Visual Studio 2010. net MVC 3 Template-select one of them to create a project using MVC 3 for you.

    The following describes some new features of preview 1. Unless otherwise stated, all the functions described here are available on the preview versions that you can download and use today. In the future, based on your feedback, more new features will appear with the release of the preview version.

    View Improvement

    ASP. net mvc 3 "Preview 1" has made many improvements in view.

    Add → view dialog box

    Preview 1 contains a new "add> View" dialog box, which allows you to select the syntax to use when creating a view template file. It allows you to choose any view engine installed on your machine-to use any view template that you feel natural.

    There are already many very good open-source view template engines (including spark, nhaml, ndjango, and some others)-we can now integrate them more easily into Visual Studio.

    In today's ASP. net mvc 3 "preview 1" version, the new view dialog box contains two built-in view engines: aspx and razor.

      New "Razor" view engine

      this is an instance used to create an online store website. It lists product categories and allows visitors to click on these categories to view related products.

      The following is the storecontroller class, which implements two execution functions ("Index" and "Browse") for the above scenario ").

      we will use the "Razor" view engine to implement the storecontroller view template.

      The following is the "layout. cshtml" layout page that defines our general layout. The "renderbody ()" method is used to specify the content filled in the view template based on the main layout page.

      The following is a view template for the index execution function. It is based on the layout page mentioned above, and then outputs a

        List of product category names.

        in the preceding template, use HTML. actionlink () This standard ASP. net MVC helper function to generate a link pointing to the "browse" execution function in our storecontroller class. All in ASP. the existing HTML auxiliary functions in. Net MVC can be used in the "Razor" view. This is not only applicable to ASP. net MVC built-in HTML helper functions are also applicable to helper functions developed by others (including those in other companies or individuals and mvccontrib projects ).

        The following is a view template created for the Browse execution function. It lists products under a category.

        note: In the preceding foreach statement, we use the model attribute to obtain the list of Strongly-typed products passed in to the Controller. This is the same as the method on the. aspx view page. Razor also allows us to use the "View" attribute to obtain the non-type "viewdata" of the incoming view page ". "View" is a dynamic attribute (this is a new function of. Net 4)-This gives us a simple and lightweight syntax to access View data (viewdata ). In this way, we only need to write view. Category instead of viewdata ["cateogry"].

      Global Filter

      ASP. net mvc supports descriptive application of the "cross-cutting" logic through filtering. You can use the attribute syntax to specify filters for controllers and execution functions, as shown below:

      ProgramDevelopers often want to apply some filter logic to all controllers in the program. Now ASP. NET mvc3 allows you to specify a global filter, which can be applied to all controllers in the program. You canRegisterglobalfilters ()Add it toGlobalfiltersThis function is included in the default global. asax class template. (Then it will be called by the application_start () function)

      In mvc3, the judgment logic of this filter is very flexible. You can configure a global filter to enable it only when certain conditions are met (for example, enable debugging, or use a specific HTTP response for a request ). The filter can be obtained from a di-dependency injection container.




















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.