ASP.NET MVC 3 Beta Released

UPDATE: This post is a out of date. We recently released the Release Candidate for ASP.NET MVC 3.

Wow! It’s been a busy two months and change since we released Preview 1 of ASP.NET MVC 3. Today I’m happy (and frankly, relieved) to announce the Beta release of ASP.NET MVC 3. Be sure to read Scott Guthrie’s announcement as well.

onward Credits: Image from ICanHazCheezburger http://icanhascheezburger.com/tag/onward/

Yes, you heard me right, we’re jumping straight to Beta with this release! To try it out…

As always, be sure to read the release notes (also available as a Word doc if you prefer that sort of thing) for all the juicy details about what’s new in ASP.NET MVC 3.

A big part of this release focuses on polishing and improving features started in Preview 1. We’ve made a lot of improvements (and changes) to our support for Dependency Injection allowing you to control how ASP.NET MVC creates your controllers and views as well as services that it needs.

One big change in this release is that client validation now is built on top of jQuery Validation in an unobtrusive manner. In ASP.NET MVC 3, jQuery Validation is the default client validation script. It’s pretty slick so give it a try and let us know what you think.

Likewise, our Ajax features such as the Ajax.ActionLink etc. are now built on top of jQuery. There’s a way to switch back to the old behavior if you need to, but moving forward, we’ll be leveraging jQuery for this sort of thing.

Where’s the Razor Syntax Highlighting and Intellisense?

This is probably a good point to stop and provide a little bit of bad news. One of the most frequently asked questions I hear is when are we going to get syntax highlighting? Unfortunately, it’s not yet ready for this release, but the Razor editor team is hard at work on it and we will see it in a future release.

I know it’s a bummer (believe me, I’m bummed about it) but I think it’ll make it that much sweeter when the feature arrives and you get to try it out the first time! See, I’m always looking for that silver lining. ;)

What’s this NuPack Thing?

That’s been the other major project I’ve been working on which has been keeping me very busy. I’ll be posting a follow-up blog post that talks about that.

What’s Next?

The plan is to have our next release be a Release Candidate. I’ve updated the Roadmap to provide an idea of some of the features that will be coming in the RC. For the most part, we try not to add too many features between Beta and RC preferring to focus on bug fixing and polish.

What others have said

Requesting Gravatar... Dan Appleyard Oct 06, 2010 12:23 AM
# re: ASP.NET MVC 3 Beta Released
This sounds fantastic! Can't wait to get my hands dirty on the beta and NuPack!
Requesting Gravatar... Rob White Oct 06, 2010 12:28 AM
# re: ASP.NET MVC 3 Beta Released
NuPack sounds interesting, are you going to do a compare and contrast with other package managers?
Requesting Gravatar... Chad Moran Oct 06, 2010 12:28 AM
# re: ASP.NET MVC 3 Beta Released
Thanks Phil and co, great stuff.

Are the caching improvements still slated for the final release of MVC 3?
Requesting Gravatar... Travis Oct 06, 2010 12:30 AM
# re: ASP.NET MVC 3 Beta Released
So Razor Syntax highlighting wont be in MVC3 final? Or just wont be in this beta release?
Requesting Gravatar... Ben Oct 06, 2010 12:32 AM
# re: ASP.NET MVC 3 Beta Released
Don't forget about the temp solution of the razor syntax highlighter available from the Visual Studio Gallery.
Requesting Gravatar... JC Grubbs Oct 06, 2010 1:09 AM
# re: ASP.NET MVC 3 Beta Released
What about the source code? Any word on when that will be released?
Requesting Gravatar... shawn Oct 06, 2010 1:15 AM
# re: ASP.NET MVC 3 Beta Released
Wow, you're iterating public releases quickly!

Any chance ASP.NET MVC 3 will have better support for binding to hierarchical model graphs, where the model contains sub-collections of other models? Right now the default model binder will clear out and re-create any existing collections rather than updating them.

Rudi Breedenraedt came up with a nice workaround, it would be great to see something like that baked into MVC 3. Search for "asp.net mvc binding model graphs" for the example/workaround (which you commented on).
Requesting Gravatar... Fujiy Oct 06, 2010 1:39 AM
# re: ASP.NET MVC 3 Beta Released
I need to reference all .js of ASP.NET MVC 2 plus this new? Or I can remove MicrosoftAjax.js, etc?

Thanks
Requesting Gravatar... Erx Oct 06, 2010 3:22 AM
# re: ASP.NET MVC 3 Beta Released
This is very dismal, I see now that there will be no feature to return multiple views in mvc 3.0, or even an elegant way to update various divs without having to make multiple requests (which force js hackery to request and blatant js hackery to split up and re assign on the receive end)... I still find it hard to believe that such a common need is not only ignored but not even acknowledged.
Requesting Gravatar... stuhin Oct 06, 2010 5:03 AM
# re: ASP.NET MVC 3 Beta Released
It is a pity that you have removed optional of @RenderSection((
Now @RenderSection("content",optional:true) - ERROR
Requesting Gravatar... Matt S. Oct 06, 2010 5:06 AM
# re: ASP.NET MVC 3 Beta Released
@Erx

Are you eluding to a feature that will allow a single request to respond with multiple distinct views that can be targeted to areas of a primary view; like child views or multiple partial views that can be slipped into separate chunks of the main view?
Requesting Gravatar... Hector Minaya Oct 06, 2010 5:11 AM
# re: ASP.NET MVC 3 Beta Released
Where is the RoadMap???
Requesting Gravatar... Fujiy Oct 06, 2010 5:27 AM
# re: ASP.NET MVC 3 Beta Released
@Hector Minaya, the roadmap is at codeplex: aspnet.codeplex.com/wikipage?title=Road%20Map
Requesting Gravatar... Sean Paul Oct 06, 2010 6:50 AM
# re: ASP.NET MVC 3 Beta Released
Weird issue I found today when playing with the newest release. If I'm using the Authorize attribute on a Action when it goes to redirect to the Login action it is always redirecting to Account\Login and not reading the Forms authentication setup in the web.config. For instance with just a default project created from the new MVC3 Template add the authorize attribute to the Index method and run the site. It will throw a 404 page not found error saying it can't find the Account/Login page where it should be going to the Account/LogOn page.
Requesting Gravatar... George Oct 06, 2010 7:11 AM
# re: ASP.NET MVC 3 Beta Released
Why did you remove the optional:true in RenderSection?? :(
Requesting Gravatar... haacked Oct 06, 2010 8:06 AM
# re: ASP.NET MVC 3 Beta Released
@George @Stuhin. The Razor team simply inverted the parameter name. Here's what you need to do now. Turns out, it couldn't be named "optional" because VB.NET already uses that as a keyword. :)


@RenderSection("content", required: false)
Requesting Gravatar... haacked Oct 06, 2010 8:06 AM
# re: ASP.NET MVC 3 Beta Released
@Travis just for this beta release.
Requesting Gravatar... haacked Oct 06, 2010 8:07 AM
# re: ASP.NET MVC 3 Beta Released
@Hector aspnet.codeplex.com/wikipage
Requesting Gravatar... Ignat Andrei Oct 06, 2010 8:49 AM
# re: ASP.NET MVC 3 Beta Released
Could you show/blog some examples about Tasked based helpers ?
Requesting Gravatar... Wayne Brantley Oct 06, 2010 9:26 AM
# re: ASP.NET MVC 3 Beta Released
(I posted this on Brad's blog too - wanted your input also)
Any improvement in validation support?

1) Need to set a range - dynamically. Say you are transferring money out your bank account. You click on the account you want to transfer from and I have a box to type in how much you want to transfer. In the controller - I can look at your balance and need to be able to set the max value at that time. It does me no good to use a static attribute.

2) Out of the box support for remote validation.

3) Put a from and to date field on a page. Make sure the from is before the to. Or have 3 or 4 date fields that are all related, say - date you are leaving on vacation, date you are returning, date you want to fly home. (leave<return, flyhome>=leave and flyhome<return)

4) Model validation - validate the model after all fields have been validated - and some way to send a javascript version of this to the client.

Are there any plans for implementation of any of these scenarios. I know I read there is some additional support for 'related field validation' in the preview (would it support option 3 above?). What about the badly needed option 1 and 2?

Requesting Gravatar... Gorazd Breskvar Oct 06, 2010 4:47 PM
# re: ASP.NET MVC 3 Beta Released
Will MVC3 support readonly concurrent session handling
using
[ControllerSessionState(ControllerSessionState.ReadOnly)] or will that part still be in MVC Futures?

Here are more details on this issue:
blog.whiletrue.com/...
Requesting Gravatar... Bm Oct 06, 2010 9:12 PM
# re: ASP.NET MVC 3 Beta Released
Phil, we need multiple views support in mvc, or a way to update multiple divs in one request like erx mentioned. This should have been in since v1 :). Anyone else think this is important?

At the moment I am queuing my requests, div one updates and sends js request to update div2 so user sees delay... Still better than the js hack option.
Requesting Gravatar... Sean Paul Oct 06, 2010 10:17 PM
# re: ASP.NET MVC 3 Beta Released
My question above is answered on Scott Guthrie's blog in one of his comments. Here is what he said.

Wednesday, October 06, 2010 6:03 PM by ScottGu

You found a bug! To work around it, add the following entry into your web.config file:

<appSettings>
<add key="autoFormsAuthentication" value="false" />
</appSettings>

(<appSettings> is a child element of <configuration>, not of <system.web>.)

This should fix it.

Thanks,
Scott
Requesting Gravatar... Danny Fafach Oct 06, 2010 11:15 PM
# re: ASP.NET MVC 3 Beta Released
I'm thrilled! Great work!

BTW, it looks like this is a typo in the release notes under the section "Upgrading an ASP.NET MVC 2 Project to ASP.NET MVC 3". Step 5 reads, "...add a reference to System.WebPages.dll and System.Web.Helpers.dll."

This should reference "System.Web.WebPages.dll".

Thanks,
-Danny
Requesting Gravatar... Danny Fafach Oct 07, 2010 1:21 AM
# re: ASP.NET MVC 3 Beta Released
Two thought:
1. In the Application_PostAuthenticateRequest() method of my Global.asax.cs file I am referencing Context.User.Identity. This install caused this identity to come back as null every time I hit a page. However, Sean's post about adding <add key="autoFormsAuthentication" value="false" /> to my Views\Web.config file fixed the problem. Thanks Sean/Scott!

2. I am getting the following runtime error on a @using directive on the top of a cshtml file:

System.Web.HttpParseException was unhandled by user code Message=Expected ";"

If I add a semicolon to the @using directive the error goes away, but then I get a ";" on my page. Adding <!-- @using namespace; --> doesn't hide the semicolon either :( Any suggestions?

Thanks,
Danny
Requesting Gravatar... Lee Oct 07, 2010 5:41 AM
# re: ASP.NET MVC 3 Beta Released
Hi Phil, i'm loving the improvements. I'm quite new to ASP.NET MVC but kind of jumped in at the deep end by starting a new project with MVC to learn it. Coming from ASP.NET Web Forms i particularly found it easy working with javascript. In ASP.NET v4 Web Forms we can now override the ClientID for any control but i believe this is not possible with the HTML helpers in MVC. I tend to name all my client id's lower case and separated by a hyphon. It would be great if there was a way to override the current naming conventions (preferably in one place).
Requesting Gravatar... Sean Paul Oct 07, 2010 6:42 AM
# re: ASP.NET MVC 3 Beta Released
@Danny, I hear you, going into all views and adding semicolons is no fun, I had to do it. My views are working fine with a ";" it doesn't show ";" on the page. But anyways, the new razor syntax for commenting is

@*{comment text here}*@
Requesting Gravatar... Germán Oct 07, 2010 5:48 PM
# re: ASP.NET MVC 3 Beta Released
Hi!,

Great bits!! Anyway, following the _ViewStart.cshtml feature for centralizing the Layout setting is a litte bit tricky.

It broke my application as the _Layout.cshtml itself is making various @Html.Action helper calls. This calls return also view (which is intended to be partial, no layout) but now with the layout globally defined they also execute the layout. So my application is making recursive calls to the @Html.Action helpers and it hangs.

I solved it by going to these views that are intended to be partial views and wrote.
@{
Layout = null;
}

This solved my problem but I think there should be a clear mechanism for marking a view as a partial view that shouldn't get any layout, no matter what a site wide setting as the _ViewStart.cshtml Layout should have been defined.

Maybe a @nolayout directive? A view naming convention?

Great work, anyway. Regards.

Germán
Requesting Gravatar... Germán Oct 07, 2010 6:05 PM
# re: ASP.NET MVC 3 Beta Released
Hi,

In regard to my previous issue, thinking for two additional seconds brought me to the real problem and the solution. In the action that was being called in the layout I was returning a normal View(). Changing it to PartialView() solved the issue an it clearly tells MVC that you don't want any layout no matter what the Razor's Engine Layout setting has been configured.

ActionResult TopMenu() {
var model = GetMenu();
return PartialView(model);
}

Germán
Requesting Gravatar... Germán Oct 08, 2010 1:57 AM
# re: ASP.NET MVC 3 Beta Released
Hi Phil,

I can't access WebViewPage.Html property from within a declarative helper (@helper) in the same cshtml file, because razor generates a static HelperResult member for the helper section. So the wrapped delegate can't access the instance members of the WebViewPage.


Example: This gives a nice compilation error CS0120 :-)

@helper MyPopulatedTextBox(string name) {

Hi @name!



Is this your name? @Html.TextBox("theName", name)


}

<h2>@View.Message</h2>


To learn more about...
MyPopulatedTextBox("John Doe");



Anyway, is there a central place to report all this issues for the Beta so your blog doesn't get bloated of boring comments like this one?

Thanks!

Germán
Requesting Gravatar... Justin Oct 08, 2010 5:39 AM
# re: ASP.NET MVC 3 Beta Released
Hi Phil,
I'm having a difficult time getting the razor view to look clean while simultaneously generate the HTML I want. The problem, for me, is in the way the white space is handled. Is there a way to stop razor from capturing white space to use in the generated output? Like @{ WhiteSpace.Ignore(); } then later turn back on white space capturing @{ WhiteSpce.Capture(); }

Thanks,
Justin
Requesting Gravatar... jmorris Oct 08, 2010 6:38 AM
# re: ASP.NET MVC 3 Beta Released
When is the MVC 4 CTP coming out?
Requesting Gravatar... Areg Sarkissian Oct 08, 2010 8:12 AM
# re: ASP.NET MVC 3 Beta Released
Will the Razor View Engine support donut caching as apposed to donut hole caching?
Requesting Gravatar... Steve Oct 09, 2010 8:11 AM
# re: ASP.NET MVC 3 Beta Released
I'm wondering why a grid was released but is client side sorting and paging only ? Quite honestly, you might as well push the MvcContrib grid instead as it offers much more. This is a very weak control being released.

I suggest making sure when this goes live that these controls are rich, useful, and fully functional.

Otherwise, just punt to people in the community (also Telerik) create good controls.

Just waiting for a young dev to through this on the page with mvc/matrix and through a 1000 records at it without understanding the implications
Requesting Gravatar... Paul Oct 10, 2010 10:08 AM
# re: ASP.NET MVC 3 Beta Released
I know it's cool to be releasing(or getting close) in 6months since V2, but geez it's getting hard to keep up.
Requesting Gravatar... Harlan Vossos Oct 11, 2010 12:49 AM
# re: ASP.NET MVC 3 Beta Released
How do you add global namespace imports for razor views? with aspx views namespaces added in the web config via the pages/namespaces setting were available. With MVC 3 preview 1, razor views could see namespaces added programitically using Microsoft.WebPages.Compilation.CodeGeneratorSettings.AddGlobalImport("") -- It appears this method no longer is available.
Requesting Gravatar... Justin Oct 11, 2010 6:46 AM
# re: ASP.NET MVC 3 Beta Released
@Harlan you can use System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport("") for global namespace imports.
Requesting Gravatar... Germán Oct 11, 2010 9:47 PM
# re: ASP.NET MVC 3 Beta Released
@Harlan, you can configure the namespaces through a new configuration section in web.config . Have a look at the default MVC 3 project and find in ~/Views/Web.config the following section

<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>


Saludos!
Requesting Gravatar... Stacey Oct 12, 2010 2:29 AM
# re: ASP.NET MVC 3 Beta Released
One thing I would really like to see with MVC 3.0 is much more intuitive support for Multi-Select Drop Downs. I realize there are half a dozen to the other solutions out there, but it seems that no matter what, it always becomes a problem in any project I do.

I would really be excited to see the MVC team address this in the future.

One thing I haven't liked about MVC 3.0 is that a lot of the features that are being touted are very unclear. What I mean by that is that they assume a very specific level of knowledge in certain aspects of "MVC", such as Dependency Injection, and IoC. I realize that from a technical community standpoint, you cannot just 'dumb down' every post made, but I feel that a lot of blog posters do not keep in mind that MANY MANY MANY of the people 'getting into MVC programming', like myself, are very unfamiliar with these concepts and the way they are presented makes it hard to understand their significance. I know I spent a great deal of time reading through ScottGu's posts on MVC 3.0 and I find myself just saying "I have no idea what any of this means".

In any case, I love how MVC 3.0 is shaping up. Keep up the good work. In all the years I've been programming, I've never seen a project evolve as quickly, and as professionally as ASP.NET MVC. I feel like we have a team that wants to make this a champion. I feel like we have a team that wants this to be a standard. I feel like we have a team that isn't cutting corners to get things done. When the MVC team releases something, it feels concrete, it feels thought out, it feels like something I can be proud to say I am using.
Requesting Gravatar... Erx Oct 13, 2010 10:18 AM
# re: ASP.NET MVC 3 Beta Released
@matt s, and @Phil: yes This is whAt I am saying, or just a proper way to be able to update multiple divs especially if one div is one top and one on bottom we have to return everything in between as a partial view to update both divs in an Ajax call. Or we split the incoming using very hackie js methods. Ideally there should be a proper way to update multiple divs in one show like the update panel in web forms allowed.

@Phil:

Will this be available in mvc3 final?
Requesting Gravatar... Venkat Oct 15, 2010 5:43 AM
# re: ASP.NET MVC 3 Beta Released
Where can i find source code for asp.net beta. In codeplex I am able to find source code for only MVC3 preview1.
Requesting Gravatar... Viewguy Oct 17, 2010 7:17 PM
# re: ASP.NET MVC 3 Beta Released
I would also like to know if updating multiple divs in one Ajax request will be available in mvc3 final
Requesting Gravatar... Maxild Oct 28, 2010 10:40 PM
# re: ASP.NET MVC 3 Beta Released
Just browsed the source for MVC 3. A lot of new code!

I am going to investigate further but the dependencies and the duplication seems a bit weird for a start.

What is this new System.Web.WebPages and System.Web.WebPages.Razor that MVC needs to build and run?

Is it really necessary to understand for a guy using a 3rd party view engine?

And why can't Razor be brought in -- from my code -- without a reference to System.Web.Razor in System.Web.Mvc? I mean, if I like to try Razor my web app project will reference it and bootstrap the engine probably referencing System.Web.Razor and 'System.Web.Mvc.Razor' (an assembly name i made up for mvc specific 'adapter' code).

Maybe this is a subject for another blog post.

P.S. Thanks for always make a preview of the source available
Requesting Gravatar... Igorbek Oct 30, 2010 2:31 AM
# re: ASP.NET MVC 3 Beta Released
I found 2 bugs in Razor view-engine.

1. I can't write any inline-templates in _ViewStart, cause

WriteLitralTo is not defined in ViewStartPage class

2. Translator inserts unnecessary whitespace writes

For ex:

_ViewStart.cshtml

@{

Func<int, HelperResult> intFormatter = @<text>- @item -</text>;

}

That code translates to:

public class _ViewStart_cshtml : System.Web.Mvc.ViewStartPage {

...

public override void Execute() {

Func<int, HelperResult> intFormatter =item => new

System.Web.WebPages.HelperResult(__razor_template_writer => {

WriteLiteralTo(@__razor_template_writer, " ");

WriteLiteralTo(@__razor_template_writer, "- ");

WriteTo(@__razor_template_writer, item);

WriteLiteralTo(@__razor_template_writer, " -");

}

}

}

So:

(1)

CS0103: The name 'WriteLiteralTo' does not exist in the current context

WriteLiteralTo is defined in System.Web.WebPages.WebPageBase, but

StartPage does not inherited from it.

(2)

Why these unnecessary WriteLiteralTo calls (" ")? - there is no in my

code. And these unnecessery calls occurs all the time even in other

views! Why? I don't need them!

If I change the code, by replacing single space by other spaces (for

ex, three tabs) between = and @:

Func<int, HelperResult> intFormatter = @<text>- @item -</text>;

translator generates:

WriteLiteralTo(@__razor_template_writer, "\t\t\t");

WriteLiteralTo(@__razor_template_writer, "- ");

...

so, it generates writes for whitespaces BEFORE @, from code context!

why? Is this bug?

Is this behaivor will be changed to release?

How to decide these problems?
Requesting Gravatar... Alexander Taran Oct 31, 2010 3:50 PM
# re: ASP.NET MVC 3 Beta Released
I know you will look into publishing scenarios later in the cicle closer to release, but meanwhile I have to report that now "publish" from within vs2010 does not include most of cshtml files, even more it confused me with including some of them.

should be more consistent way to include all assemblies needed to run mvc3 razor website into bin directory.

Keep up the good work. MVC is awesome.
Requesting Gravatar... borgman Nov 02, 2010 12:27 AM
# re: ASP.NET MVC 3 Beta Released
When is Intellisense-support coming? Could you give a rough estimate?

What do you have to say?

(will show your gravatar)
Please add 8 and 1 and type the answer here: