当前位置:首页 > 开发教程 >

ASP.NET MVC 3

时间:2013-04-26 15:47 来源:网络整理 作者:采集侠 收藏

(includes April 2011 Tools Update) ASP.NET MVC 3 is a framework for building scalable, standards-based web applications using well-established design

/ASP.NET MVC 3

ASP.NET MVC 3

(includes April 2011 Tools Update)

ASP.NET MVC 3 is a framework for building scalable, standards-based web applications using well-established design patterns and the power of ASP.NET and the .NET Framework.

It installs side-by-side with ASP.NET MVC 2, so get started using it today!

Install MVC3 Free
or download the installer here

Top Features Top Links

What's New in ASP.NET MVC 3

Installation and Help

ASP.NET MVC 3 Overview

ASP.NET MVC 3 builds on ASP.NET MVC 1 and 2, adding great features that both simplify your code and allow deeper extensibility. This topic provides an overview of many of the new features that are included in this release, organized into the following sections:

Extensible Scaffolding with MvcScaffold integration

The new Scaffolding system makes it easier to pick up and start using productively if you’re entirely new to the framework, and to automate common development tasks if you’re experienced and already know what you’re doing.

This is supported by new NuGet scaffolding package called MvcScaffolding. The term “Scaffolding” is used by many software technologies to mean “quickly generating a basic outline of your software that you can then edit and customize”. The scaffolding package we’re creating for ASP.NET MVC is greatly beneficial in several scenarios:

Other features in MvcScaffolding include:

The ASP.NET MVC 3 Tools Update includes great Visual Studio support for this scaffolding system, such as:

  • Add Controller Dialog now supports full automatic scaffolding of Create, Read, Update, and Delete controller actions and corresponding views. By default, this scaffolds data access code using EF Code First.
  • Add Controller Dialog supports extensible scaffolds via NuGet packages such as MvcScaffolding. This allows plugging in custom scaffolds into the dialog which would allow you to create scaffolds for other data access technologies such as NHibernate or even JET with ODBCDirect if you’re so inclined!
  • For more information about Scaffolding in ASP.NET MVC 3, see the following resources:

  • Steve Sanderson's post series, including:
  • Scott Hanselman's post from his PDC 2010 session Building a Blog with Microsoft "Unnamed Package of Web Love"
  • MVC 3 Release Notes
  • HTML 5 Project Templates

    The New Project dialog includes a checkbox enable HTML 5 versions of project templates. These templates leverage Modernizr 1.7 to provide compatibility support for HTML 5 and CSS 3 in down-level browsers.

    The Razor View Engine

    ASP.NET MVC 3 comes with a new view engine named Razor that offers the following benefits:

    Some new Razor features include the following:

    Razor also includes new HTML helpers, such as the following:

    For more information about Razor, see the following resources:

    Support for Multiple View Engines

    The Add View dialog box in ASP.NET MVC 3 lets you choose the view engine you want to work with, and the New Project dialog box lets you specify the default view engine for a project. You can choose the Web Forms view engine (ASPX), Razor, or an open-source view engine such as Spark, NHaml, or NDjango.

    Controller Improvements Global Action Filters

    Sometimes you want to perform logic either before an action method runs or after an action method runs. To support this, ASP.NET MVC 2 provided action filters. Action filters are custom attributes that provide a declarative means to add pre-action and post-action behavior to specific controller action methods. However, in some cases you might want to specify pre-action or post-action behavior that applies to all action methods. MVC 3 lets you specify global filters by adding them to the GlobalFilters collection. For more information about global action filters, see the following resources:

  • Scott Guthrie's blog on the MVC 3 Preview
  • Filtering in ASP.NET MVC
  • New "ViewBag" Property

    MVC 2 controllers support a ViewData property that enables you to pass data to a view template using a late-bound dictionary API. In MVC 3, you can also use somewhat simpler syntax with the ViewBag property to accomplish the same purpose. For example, instead of writing ViewData["Message"]="text", you can write ViewBag.Message="text". You do not need to define any strongly-typed classes to use the ViewBag property. Because it is a dynamic property, you can instead just get or set properties and it will resolve them dynamically at run time. Internally, ViewBag properties are stored as name/value pairs in the ViewData dictionary. (Note: in most pre-release versions of MVC 3, the ViewBag property was named the ViewModel property.)

    New "ActionResult" Types

    The following ActionResult types and corresponding helper methods are new or enhanced in MVC 3:

    JavaScript and Ajax Improvements

    By default, Ajax and validation helpers in MVC 3 use an unobtrusive JavaScript approach. Unobtrusive JavaScript avoids injecting inline JavaScript into HTML. This makes your HTML smaller and less cluttered, and makes it easier to swap out or customize JavaScript libraries. Validation helpers in MVC 3 also use the jQueryValidate plugin by default. If you want MVC 2 behavior, you can disable unobtrusive JavaScript using a web.config file setting. For more information about JavaScript and Ajax improvements, see the following resources:

    Client-Side Validation Enabled by Default

    开发教程阅读排行

    最新文章