ASP.NET MVC 3 preview analyze

ASP.NET MVC 3 is new version of fresh Framework and it is available for download as preview. ASP.NET MVC 3.0 compatible with ASP.NET MVC 2 – which means it will be easy to update projects you are writing with MVC 2 to MVC 3 when it finally releases.  The new features in MVC 3 build on top of the foundational work we’ve already done with the MVC 1 and MVC 2 releases – which means that the skills, knowledge, libraries, and books you’ve acquired are all directly applicable to MVC version 3.  MVC 3 adds new features and capabilities – it doesn’t obsolete existing ones.ASP.NET MVC 3 can be installed side-by-side with ASP.NET MVC 2, and you can install today’s “Preview 1” release on your machine without it impacting existing MVC 2 projects you are working on (they will continue to use MVC 2 unless you explicitly modify the plans to retarget them to ASP.NET MVC 3 preview). 

When you install “Preview 1” you will have a new set of ASP.NET MVC 3 project templates show up within Visual Studio 2010’s “New Project” dialog – choosing one of those when you create a new project will cause it to use MVC 3. Below are details about some of the new features and capabilities in today’s “Preview 1” release.  Unless otherwise noted, all of the features I describe are enabled with the preview build you can download ASP.NET MVC 3 and use today.  More ASP.NET MVC 3 features will come in future preview refreshes as we flesh out the product more and iterate on your feedback.ASP.NET MVC 3 is the next major release of ASP.NET MVC. And I want to discuss new preview version features with help of Haacked and ScottGu articles.

  Razor

 

In this episode, James Senior talks to Phil Haack, Senior PM on the ASP.NET MVC team, about ASP.NET MVC 3 Preview 1. Phil shows off his demo skills as he takes us on a tour of the new Razor syntax and highlights some tips and tricks on how to use it. He also talks about his favorite new features in ASP.NET MVC 3, including Dependency Injection, .NET 4 Data Annotation support, and the custom view engine dialog!


Get Microsoft Silverlight
For more information check out the following links:

Scott sneaks into the office of Phil Haack and Morgan, the Canadian Intern, to talk about the release of ASP.NET MVC 3 Preview 1 and some of the cool "futures" stuff that Morgan (and our fleet of interns) is working on.

Get Microsoft Silverlight

ASP.NET MVC has always supported the concept of “view engines” – which are the pluggable modules that implement different template syntax options.  The “default” view engine for ASP.NET MVC today uses the same .aspx/.ascx/.Master file templates as ASP.NET Web Forms.  Other popular ASP.NET MVC view engines used today include Spark and NHaml.

Below is a StoreController class that implements the two action methods (“Index” and “Browse”) needed to build the above scenario:

We’ll use the new “Razor” view engine to implement the view templates for our StoreController.

Below is the “Layout.Cshtml” layout-page that will define the common layout UI we want across our site.  The “RenderBody()” method indicates where view templates that are based on this master layout file should “fill in” the body content:

ASP.NET MVC 3

Razor syntax example, not that you can use '@' syntax without <% %> anymore, but it does not support Visual Studio IntelliSense yet.

Razor syntax

The new view-engine option we’ve been working on is optimized around HTML generation using a code-focused templating approach. The codename for this new view engine is “Razor”, and we’ll be shipping the first public beta of it shortly. Design Goals are pretty simple.

Compact, Clean, Expressive Code

One of the things to notice in the code above is that the syntax for defining layouts and using them from views/pages is clean and minimal.  The code screen-shots above of the SiteLayout.cshtml and Home.cshtml files contain all of the content in the two .cshtml files – there is no extra configuration or additional tags, no <%@ Page%> prefix, nor any other markup or properties that need to be set.

We are trying to keep the code you write compact, smooth and fluid.  We also want to enable anyone with a text editor to be able to open, edit and easily tweak/customize them.  No code generation or intelligence required.

Razor

We had several design goals in mind as we prototyped and evaluated “Razor syntax”:

  • Compact, Expressive, and Fluid: Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to denote server blocks within your HTML explicitly. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.
  • Easy to Learn: Razor is easy to learn and allows you to be productive with a minimum of concepts quickly. You use all your existing language and HTML skills.
  • Is not a new language: We consciously chose not to create a new imperative language with Razor. Instead we wanted to enable developers to use their existing C#/VB (or other) language skills with Razor, and deliver a template markup syntax that enables an awesome HTML construction workflow with your language of choice.
  • Works with any Text Editor: Razor doesn’t require a particular tool and allows you to be productive in any plain old text editor (notepad works great).
  • Has great Intellisense: While Razor has been designed not to require a particular tool or code editor, it will have remarkable statement completion support within Visual Studio. We’ll be updating Visual Studio 2010 and Visual Web Developer 2010 to have full editor IntelliSense for it.
  • Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).
  • We’ve spent the last few months building applications with it and doing lots of usability studies of it with a variety of volunteers (including several groups of non-.NET web developers). The feedback so far from people using it has been great.

As I mentioned earlier, one of our goals with Razor is to minimize typing, and enable it to be easily edited with nothing more than a basic text editor (notepad works great).  We’ve kept the syntax clean, compact and straightforward to help enable that. We have also designed Razor so that you get a rich code editing experience within Visual Studio.  We will provide full HTML, JavaScript and C#/VB code intellisense within Razor based files:

Vsiaul Studio 2010


Notice above how we are providing intellisense for a Product object on the “@p.” code embedded within the <li> element inside a foreach loop.  Also notice how our \Views folder within the Solution Explorer contains both .aspx and .cshtml view templates.  You can use multiple view engines within a single application – making it easy to choose whichever syntax feels best to you.

"Razor" - new view engine for ASP.NET provides a great new view-engine option that is streamlined for code-focused templating.  It a coding workflow that is fast, expressive and fun.  It’s syntax is compact and reduces typing – while at the same time improving the overall readability of your markup and code.  It will be shipping as a built-in view engine with the next release of ASP.NET MVC.  You can also drop standalone .cshtml/.vbhtml files into your application and run them as single-pages – which also enables you to take advantage of it within ASP.NET Web Forms applications as well.

References:

Summary:

As we can see code is going to be simpler with new syntax. Also it is very cool that we have all features from ASP.NET version 4.0. But disadvantages of such approach is that we cannot support Visual Studio 2008 or Visual Studio 2005 anymore. All new releases will be concentrated only on 2010 IDE and it is really uncomfortable for projects that already working on 2008 IDE and with team contains many peoples. What do you think about ASP.NET MVC 3?

Comments (4) -

  • Thanks for taking the time to share this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
  • @Binary Options, sure man. I will do my best for sharing more interesting articles regarding to ASP.NET MVC Framework.
  • Thanks for sharing this post. Best regards and well wishes for your future endeavors.
  • Moncler, do you know how to convert asp.net mvc 2 to 3 beta?

Pingbacks and trackbacks (1)+

Add comment

Loading