ASP.NET MVC 4 Beta

A few days ago we released the ASP.NET MVC 4 Beta.  This is a significant release that brings with it a bunch of great new features and capabilities. 

The ASP.NET MVC 4 Beta release works with VS 2010 and .NET 4.0, and is side-by-side compatible with prior releases of ASP.NET MVC (meaning you can safely install it and not worry about it impacting your existing apps built with earlier releases).  It supports a “go-live” license that allows you to build and deploy production apps with it.  Click here to download and install it today.

The ASP.NET MVC 4 Beta will also be built-into the upcoming VS11 / .NET 4.5 beta that is coming out shortly.  This week’s beta doesn’t work with the previous VS11 developer preview that shipped last September – if you are using the VS11 Developer Preview (or have it installed) you’ll want to wait until the VS 11 beta is released before trying out the new ASP.NET MVC 4 Beta functionality.

ASP.NET MVC 4 Features

The ASP.NET MVC 4 Beta includes a bunch of great new features and capabilities.  Some of the highlights include:

  • Bundling and Minification – ASP.NET MVC 4 includes the new bundling and minification support we are also adding to ASP.NET 4.5.  These features enable you to build web applications that load faster and feel more responsive to users, by minimizing the number and size of HTTP requests that your pages make.  Included with the MVC 4 beta are new “cache busting” helper methods that enable easy proxy caching of bundled files (with automatic invalidation if you change the cached CSS or JavaScript).  You can learn more about bundling and minification from my previous blog post about it.
  • Database Migrations – ASP.NET MVC 4 includes the new Entity Framework 4.3 release, which includes a bunch of great new features.  One of the most eagerly anticipated features it provides is database migration support.  This enables you to easily evolve your database schema using a code focused migration approach – and do so while preserving the data within your database.  I’ll blog more about this in the future - you can also see a walkthrough of database migrations in this tutorial.
  • Web API – ASP.NET MVC 4 includes some fantastic new support for creating “Web APIs”.  This enables you to easily create HTTP services and APIs that can be programmatically called from a broad range of clients (ranging from browsers using JavaScript, to native apps on any mobile/client platform).  The new Web API support also provides an ideal platform for building RESTful services.  I’ll be blogging much more about this support soon – it is really cool, and opens up a bunch of new opportunities.  There are several tutorials, samples and screencasts covering ASP.NET Web API on the ASP.NET site to help you get started.
  • Mobile Web – ASP.NET MVC 4 includes new support for building mobile web applications and mobile web sites, and makes it much easier to build experiences that are optimized for phone and tablet experiences. It includes jQuery Mobile, and includes new support for customizing which view templates are used depending upon what type of device is accessing the app.  See the ASP.NET MVC 4 tutorial series.
  • Razor Enhancements – ASP.NET MVC 4 includes V2 of our Razor View engine.  Razor V2 includes a bunch of juicy enhancements that enable you to make your view templates even cleaner and more concise – including better support for resolving URL references and selectively rendering HTML attributes.
  • Async Support and WebSockets – You’ll be able to take advantage of some additional language and runtime capabilities when using ASP.NET MVC 4 with .NET 4.5 and VS 11.  Async support is one of the big ones, and the ASP.NET MVC runtime support for this combined with the new C#/VB async language enhancements (which are super elegant and clean) is going to enable you to write incredibly scalable applications.  You will also be able to take advantage of the new WebSocket support built-into .NET 4.5 to build applications with even richer browser/server communication.

I’ll be blogging a lot more about the above features in the weeks and months ahead.  This is going to be an exciting release. There is a lot there that will both make you more productive (Bundling/Minification, Database Migrations, Razor V2) as well as enable you to build even richer web applications and experiences (Web API, Mobile Web, WebSockets).

Learning More About ASP.NET MVC 4

I gave a tech-talk about the new ASP.NET MVC 4 Beta at the Belgium and Dutch TechReady events last week.  It provides a good overview that you can use to quickly come up to speed on the release.

You can watch or download a video of the talk for free via Channel9:

image

You can also download my slides (feel free to re-use them however you want).

Summary

I’m really excited about the upcoming ASP.NET releases we have coming out this year.  ASP.NET 4.5 and ASP.NET MVC 4 are going to deliver a ton of new capabilities and enhancements, and the tooling updates we have coming with VS 11 and WebMatrix make the developer experience awesome.

I’ll be blogging a lot more about them in the weeks and months ahead.

Hope this helps,

Scott

P.S. In addition to blogging, I use Twitter to-do quick posts and share links. My Twitter handle is: @scottgu

59 Comments

  • All apps now should be built on top of an API. The WebAPI is a great feature.

  • Can you fix the Empty Project Template, to actually be Empty. Rather than have 30 different packages installed by default...

  • Wow, lots of great stuff coming with ASP.NET MVC 4. Nice work all!

  • Hi Scott,

    The SPA support looks great!
    How does the CoffeeScript/Less support work? i.e. what JS engine does it use?

  • Hi Scott,

    Thank you for the interesting overview of the new features in MVC 4. One question though.

    I'm interested in the bundling/minification feature, I've been using YUI Compressor task for msbuild to do minification/bundlin during deployment, it's nice that this functionality will be available out of the box with MVC 4. The problem that I came across though is that many of third-party libraries include license terms in them which I did not find a good way to preserve after minification/bundling process. Is there something in MVC 4 that allows to easily solve this problem?

  • 1. I experience that bug daily; it's usually right after starting VS and only when opening a Razor file. The workaround is to switch to a C# file and then back to Razor. When back in the Razor file type something before using the arrow keys (seems to unlock it). 2. Are there more features for MVC4 in the pipeline? 3. Will we see more releases before the final release? Thanks.

  • I believe it could be very important to add webmatrix.webdata and webmatrix.websecurity project in order to speed up the process to create a new website. webmatrix with webpages security system - like the one display in starter site template - is great compared to the current forms authentication with default membership provider. I hope to see that soon as a template when you start a project.
    brgds and great work!.

  • You should see what Pedro felix did with web API and the sevice bus relay! Ask GBLOCK for more info.

  • It doesn't seem the CoffeeScript and Less bundlers are a part of the Beta release. Is this correct?

  • Will server WebSockets still require Windows Server 8 due to updates to http.sys?

  • How come that Entity Framework is part of ASP.NET MVC release?

  • You should note that your November Minification article is out of date with the bits. Several key points have changed.

  • My boss says, "When they provide enum support in EF, _then_ I'll switch."

    When's V5 out, Scott?

  • Hi, can minification features work for html file (e.g. MVC page) as well besides css/js?

  • Great to see that you are embracing creating WebAPI based services, can we also expect better tooling for working with WebAPI on the client side? Currently all framework classes that deal with requests/reposes (eg. HttpWebRequest / HttpWebResponse) throw exceptions when a StatusCode is != an expected one.

    It would be great to be able to be able to omit this check based on StatusCode and handle multiple status codes.
    In fact when looking at the jQuery ajax method and it's ability to specify different execution paths based on the response (as shown in your sample) I'm getting kind of jealous since it's tedious to create a WebAPI client in C# today.

  • Excellent. There is a lot of stuff on this one. We have an old Open Rasta app that we want to update to use the web api.

  • I have to echo the question as to why EF is included. If anything, EF should be on its way out the door kicking and screaming as it's pretty awful and frankly, the samples you all put out with direct inclusion of data inside of controllers is a pretty god awful pattern.

    Please have pity on those of us that have to *un*-train people from following this unholy coupling of technologies - one of which is great- the other of which is the spawn of hell.

  • Yay! Waiting for this!

  • Hi Scott,

    As mentioned in the ASP.Net MVC 4 Roadmap:
    "...Support for claims-based authentication using Windows Identity Framework(WIF)..."
    Is out-of-the-box support for WIF coming in the near future?

  • Thanks, haven't seen you for a long time! when will VS2011 beta be released?

  • Awesome stuff!! Quick question: How does the Web API stuff relate to WCF? Are they completely independent? Does Web API support SOAP or traditional web services?

  • As Stilgar says, why bundle EF with Asp.net MVC 4? This smells like old Microsoft tactics to push own technologies. Don't destroy the the trust you have started to build up by being open with the community.

    Regards,
    Jeep

  • Thanks for your demo, I learned a lot about new features of ASP.net mvc 4

  • Great news, mvc 4 rocks! IS there a way to include the bundle items separately for debugging purposes?

    Also, what happened on around 28' mark, with the keyboard delete getting stuck is also happening to me and others some times. The workaround is to close the current working document, and reopen it. Is there a place to file this bug?

  • So far it all looks great, but regarding the bundling / minification.. How does it know what order the css files should be bundled in? You won't just want it in the order of files in the folder as styles could be overwritten.

  • Scott, I am building a MVC app that also allows other system to access its features programmatically. Do you think it is a good idea to use Web API to support both usages, i.e. to support the presentation layer as well? Thanks.

  • very nice mr Guthrie.
    i am newbie in mvc3
    but work with collection(queryable,ienumerable)is very hard.
    sorry for my bad english.

  • Great tech talk! You mentioned in the tech talk, the Web API will have OpenAuth support. ETA on RTM?

  • Hi. The new release sounds exciting, and I am buying server hardware to finally deploy my site internally. What I would really enjoy from a great presenter like you is, instead of only lengthy "specialization" blogs about individual features, I would love a video that takes me through EACH and ALL features of an "average" web site deployment. The ultimate "hello world" video, if you will. Use all the major new features that would help someone (like me, and countless others) get a basic "step-by-step" method for deploying the following (if not, more): ASP.Net MVC 4 on mobile and regular browsers, using EF4 to migrate a simple customer form feedback database (so, customers can say "howdy, world"), use the Mobile and regular jQuery stuff a bit, do a bit of SEO jazz, maybe a browser discovery arrangement, and a "submit" button. If you're really feeling squirrelly (sp?), then send the data to/from Azure. Scale it up if the user gets a bunch of hits? Then, when you have a real life application prototype (void)... you send it to godaddy (or wherever the hell)... the reason I think you should do this "full hello world" is you are the best of a generation of speakers, and you would put the right spin on it... ask around...

  • @DrAlligieri I ran into the same thing you did at first and then noticed that when creating a site, by default it adds BundleTable.Bundles.RegisterTemplateBundles(); inside of the global.asax.cs file. When I commented out this line and put in BundleTable.Bundles.EnableDefaultBundles(); then things started to work. I am not sure why they default to this behavior for minification, so maybe Scott can shed some light on that explanation. Either way, by changing that line, things should work for you (I found this line in the video when Scott was showing how to create his own custom bundles, so even he had the change in place in order to get his example to work).

    Again Scott, great talk, and as @bgrebil pointed out, any hints as to where we can find the Coffee and Less bundling code that you used in your demo?

  • For those wondering "why include EF with this release?", if you watch the video, it goes into more detail...Basically, EF is not a part of MVC 4 even though MVC 4 works well with the new release of EF. It is separate from MVC and can be used in other project types (i.e. webforms, wpf, etc...).

    Listing EF with the other "features" of this release is a bit confusing, but the video does clear it up a bit.

  • great list of features.

    Any comment on when to use the new Web API vs WCF data services


    thanks

  • i wonder in asp.net web api you no longer need a wcf service in place, so is it the end of WCF?

    WCF web api was working fine with webGet, WebInvoke, UriTemplate, so why this is shifted to asp.net web api to bring the controller style ?

    Now tell if i want to expose my WCF api in a rest full way over http how can i do this? will i use wcf web api style means webGet /Invoke/ UriTemplate ?

    Thanks in advance.

  • "meaning you can safely install it and not worry about it impacting your existing apps built with earlier releases"

    Well, my ASP.NET MVC3-based Azure project now doesn't deploy properly... gives me errors about assemblies not matching their manifests...

  • Wow, I never thought MVC could bring us more then 3 already offers. I like the improvements on Razor and the bundling/minification solution, but most of the, the API implementation is excellent. Thanks for your great presentation.

    Good to see by the way, that the Guru suffers the same problems in VS we all have ;)

  • By the way, forgot to ask if you'll be in the Netherlands again in June during the TechEd?

  • Awesome stuff. When is this going to be released?

  • thats great to know about it. thank you!

  • Will any of this require IIS 8?

  • great to know abt new thing...thanks

  • @DrAlligieri, I ran into the same issue that you did, but found the templates add the following line to the global.asax.cs file: BundleTable.Bundles.RegisterTemplateBundles(); which will only minify the files that were added by the template. In order to get it to bundle and minify your custom files, you will want to comment out that line and add BundleTable.Bundles.EnableDefaultBundles(); instead (I saw this line in Scott's video when he was showing the CoffeeMinify piece in his video).

    Couple of questions for you Scott
    - Why do you include the RegisterTemplateBundles instead of the EnableDefaultBundles by default?
    - Will the Coffee and Sass minify/bundling be included in the final release?

    Great overview of what is available and the enhancements from 3 to 4 are great. I really appreciate the examples you have included in the out of the box templates.

  • DrAlligieri - I found the same problem you did when I first tried to play with the bundling/minification and found that the default templates include the following within the global.asax.cs file: BundleTable.Bundles.RegisterTemplateBundles(); If you comment out this line and add BundleTable.Bundles.EnableDefaultBundles(); (which was a line I found in the video that Scott posted when he was talking about the Coffee Script minification).

    Scott - Great video and great work on the enhancements to the MVC platform. I really love the default templates that are being created, they give a great starting point and reference points for someone to get up and running with a decent application fairly quick. Couple of questions for you, though:
    - Will you be including the CoffeeScript and Sass bundling code that you showed in your demo in the final release?
    - Why do the default templates not have BundleTable.Bundles.EnableDefaultBundles(); set by default? It might avoid some confusion for many developers down the line who are trying to get the bundling and minification working with their custom css and js files.

  • Why so much attention is paid to EF? ORMs and Web Apps are not big friends and EF by itself is so slow and inefficient that it suites for demos only and for relatively small and simple databases.
    It is sad that MVC4 adds so little to MVC3. Why not to give Razor it's own life - so we could use it not only in MVC apps? Maybe some support for CDN could be also useful. Razor still has very limited support for markup functions (lambda razor functions would be great:
    @Grid.TemplateCol(i=>{@i}) - maybe it's possible to write this in MVC3?

  • Awesome work!

    Any chance of a future blog post showing how to create a WCF service that works with jsonp data?

    I've been told that it can be done simply using the Web API functionality, but I can't seem to find any documentation anywhere.

    Also, I've also been told that one limitation is that the wcf service would not be able to handle post jsonp requests that tries to pass in complex types, is this true?

  • You should rename ApiController into ResourceController. What a Web Api exposes is a resource.
    You should also add some extension methods for the RouteCollection class to route incoming requests by Http header Accept value; for instance, MapHttpResourceRoute(...). Therefore no "api/" part would be required in app urls...
    Nice work, I'm enjoying MVC a little more every day!

  • @kozlow - an ApiController may expose more than one resource type. I suppose using the Resource/REST approach is just one design scenario that a developer can opt into using.

  • nice one

  • Hi Scott,

    How do I file a bug for MVC4?

    I found a bug regarding the xml serialization.

    When I have a class with a System.Uri property, the XmlSerializer throws an exception that it can not serialize the type and what happens is that I get a json back even though I requested xml.

  • I've worked on MVC 1 & 2 projects before, is there a major performance increase from the past versions?

  • Hi Scott,

    In anticipation of the new VS11 and .NET 4.5 I have a short question concerning Windows Azure. The last .NET 4 release took a long time before included in Azure OS images. This is a pity, especially since Azure is a great platform to develop and test new technologies on.

    Ideally many developers would like to start using .NET 4.5 on Azure from beta day 1. Isn't it possible to create a 'cutting-edge' OS family, let's say 0.XX, which is not officially supported but always runs the latest versions of Windows & .NET?

    This will definitely help the quick adoption of new technologies and may boost the usage of Azure since developers are already testing their software on Azure...

    Thanks, Djon

  • "I found a bug regarding the xml serialization.
    When I have a class with a System.Uri property, the XmlSerializer throws an exception that it can not serialize the type and what happens is that I get a json back even though I requested xml."

    This is a known issue. We are considering to not to fall back on to Json in the future releases when expecting xml. But for this specific scenario, you are required to change the formatter to use DataContractSerializer as below.

    GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseDataContractSerializer = true;

  • really...
    Microsoft is great...

  • Hi Scott

    Can you create an excel file upload page maybe even using a web api's so I can upload the thousands of bugs I deal with on a regular basis in Visual Studio and .NET in batch? This would be a lot easier then entering them in one at a time into some website.

    You know what would be really exciting is if you quit adding new features that probably don't work well in any NON-DEMO application anyway and actually fixed the bugs in your product.

    Isn't that a freaking EPIC idea!





  • Hi Scott,

    We have recently upgraded the MVC2(with LINQ to SQL) application to MVC4(With EF). We are having a severe performance issue after the upgrade. I have posted a thread at http://forums.asp.net/t/1785359.aspx/1?RE+Performance+issue+after+upgrading+MVC2+from+L2S+to+EF

    With some feedbacks, we were able to notice that its due to Dependency Injection. When we have no Interfaces in the Constructor, the page loads faster as it was with MVC2, but if I add those Interfaces back to Constructor, the page loads slower.

    Is there anything that needs to be followed for Dependency Injection particularly to MVC4? Since this is Beta, do we need to wait for the RC before looking at the performance? Any help would be appreciated

  • I haven't had a chance to try the beta yet, but I was wondering if it fixes the issue in MVC 3 where the contents of the ViewBag of child views does not bubble up to parent views unless you do some kind of refresh of the dynamic property? I've been forced to put the following code at the top of every view in order to make everything work:

    ViewBag.Scripts = (ViewBag.Scripts == null ? new System.Collections.Generic.Dictionary() : ViewBag.Scripts);

  • Hi Scott,
    When is the expected date of final release?
    Thanks,
    Khurram

  • Hi,

    I have a MVC 4 project. After successfully adding a Controller (using SPA template) and compiling, I tried to add another controller but on the Add Controller dialog there this message saying "No model classes are available".
    I think it happens after I NuGet EF 4.3 (upgrading from 4.1).

    Anyone has a solution?
    Thanks,
    Sagy

  • Hi Scott,

    I am really looking forward for MVC 4 final release, when it is expected to get a final version of MVC 4

  • The bundling and min does not work as advertised...
    You have to append it with @System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("/styles/css")

    Please be clear next time.

Comments have been disabled for this content.