Announcing ASP.NET MVC 3 (Release Candidate 2)

Earlier today the ASP.NET team shipped the final release candidate (RC2) for ASP.NET MVC 3.  You can download and install it here.

Almost there…

Today’s RC2 release is the near-final release of ASP.NET MVC 3, and is a true “release candidate” in that we are hoping to not make any more code changes with it.  We are publishing it today so that people can do final testing with it, let us know if they find any last minute “showstoppers”, and start updating their apps to use it.  We will officially ship the final ASP.NET MVC 3 “RTM” build in January.

Works with both VS 2010 and VS 2010 SP1 Beta

Today’s ASP.NET MVC 3 RC2 release works with both the shipping version of Visual Studio 2010 / Visual Web Developer 2010 Express, as well as the newly released VS 2010 SP1 Beta

This means that you do not need to install VS 2010 SP1 (or the SP1 beta) in order to use ASP.NET MVC 3.  It works just fine with the shipping Visual Studio 2010.  I’ll do a blog post next week, though, about some of the nice additional feature goodies that come with VS 2010 SP1 (including IIS Express and SQL CE support within VS) which make the dev experience for both ASP.NET Web Forms and ASP.NET MVC even better.

Bugs and Perf Fixes

Today’s ASP.NET MVC 3 RC2 build contains many bug fixes and performance optimizations.  Our latest performance tests indicate that ASP.NET MVC 3 is now faster than ASP.NET MVC 2, and that existing ASP.NET MVC applications will experience a slight performance increase when updated to run using ASP.NET MVC 3.

Final Tweaks and Fit-N-Finish

In addition to bug fixes and performance optimizations, today’s RC2 build contains a number of last-minute feature tweaks and “fit-n-finish” changes for the new ASP.NET MVC 3 features.  The feedback and suggestions we’ve received during the public previews has been invaluable in guiding these final tweaks, and we really appreciate people’s support in sending this feedback our way. 

Below is a short-list of some of the feature changes/tweaks made between last month’s ASP.NET MVC 3 RC release and today’s ASP.NET MVC 3 RC2 release:

jQuery updates and addition of jQuery UI

The default ASP.NET MVC 3 project templates have been updated to include jQuery 1.4.4 and jQuery Validation 1.7. 

We are also excited to announce today that we are including jQuery UI within our default ASP.NET project templates going forward.  jQuery UI provides a powerful set of additional UI widgets and capabilities.  It will be added by default to your project’s \scripts folder when you create new ASP.NET MVC 3 projects.

Improved View Scaffolding

The T4 templates used for scaffolding views with the Add-View dialog now generates views that use Html.EditorFor instead of helpers such as Html.TextBoxFor. This change enables you to optionally annotate models with metadata (using data annotation attributes) to better customize the output of your UI at runtime.

The Add View scaffolding also supports improved detection and usage of primary key information on models (including support for naming conventions like ID, ProductID, etc).  For example: the Add View dialog box uses this information to ensure that the primary key value is not scaffold as an editable form field, and that links between views are auto-generated correctly with primary key information.

The default Edit and Create templates also now include references to the jQuery scripts needed for client validation.  Scaffold form views now support client-side validation by default (no extra steps required).  Client-side validation with ASP.NET MVC 3 is also done using an unobtrusive javascript approach – making pages fast and clean.

[ControllerSessionState] –> [SessionState]

ASP.NET MVC 3 adds support for session-less controllers.  With the initial RC you used a [ControllerSessionState] attribute to specify this.  We shortened this in RC2 to just be [SessionState]:

image

Note that in addition to turning off session state, you can also set it to be read-only (which is useful for webfarm scenarios where you are reading but not updating session state on a particular request).

[SkipRequestValidation] –> [AllowHtml]

ASP.NET MVC includes built-in support to protect against HTML and Cross-Site Script Injection Attacks, and will throw an error by default if someone tries to post HTML content as input.  Developers need to explicitly indicate that this is allowed (and that they’ve hopefully built their app to securely support it) in order to enable it.

With ASP.NET MVC 3, we are also now supporting a new attribute that you can apply to properties of models/viewmodels to indicate that HTML input is enabled, which enables much more granular protection in a DRY way.  In last month’s RC release this attribute was named [SkipRequestValidation].  With RC2 we renamed it to [AllowHtml] to make it more intuitive:

image

Setting the above [AllowHtml] attribute on a model/viewmodel will cause ASP.NET MVC 3 to turn off HTML injection protection when model binding just that property.

Html.Raw() helper method

The new Razor view engine introduced with ASP.NET MVC 3 automatically HTML encodes output by default.  This helps provide an additional level of protection against HTML and Script injection attacks.

With RC2 we are adding a Html.Raw() helper method that you can use to explicitly indicate that you do not want to HTML encode your output, and instead want to render the content “as-is”:

image

ViewModel/View –> ViewBag

ASP.NET MVC has (since V1) supported a ViewData[] dictionary within Controllers and Views that enables developers to pass information from a Controller to a View in a late-bound way.  This approach can be used instead of, or in combination with, a strongly-typed model class.  The below code demonstrates a common use case – where a strongly typed Product model is passed to the view in addition to two late-bound variables via the ViewData[] dictionary:

image

With ASP.NET MVC 3 we are introducing a new API that takes advantage of the dynamic type support within .NET 4 to set/retrieve these values.  It allows you to use standard “dot” notation to specify any number of additional variables to be passed, and does not require that you create a strongly-typed class to do so. 

With earlier previews of ASP.NET MVC 3 we exposed this API using a dynamic property called “ViewModel” on the Controller base class, and with a dynamic property called “View” within view templates.  A lot of people found the fact that there were two different names confusing, and several also said that using the name ViewModel was confusing in this context – since often you create strongly-typed ViewModel classes in ASP.NET MVC, and they do not use this API. 

With RC2 we are exposing a dynamic property that has the same name – ViewBag – within both Controllers and Views.  It is a dynamic collection that allows you to pass additional bits of data from your controller to your view template to help generate a response.  Below is an example of how we could use it to pass a time-stamp message as well as a list of all categories to our view template:

image

Below is an example of how our view template (which is strongly-typed to expect a Product class as its model) can use the two extra bits of information we passed in our ViewBag to generate the response.  In particular, notice how we are using the list of categories passed in the dynamic ViewBag collection to generate a dropdownlist of friendly category names to help set the CategoryID property of our Product object. 

image

The above Controller/View combination will then generate an HTML response like below. 

image 

Output Caching Improvements

ASP.NET MVC 3’s output caching system no longer requires you to specify a VaryByParam property when declaring an [OutputCache] attribute on a Controller action method.  MVC3 now automatically varies the output cached entries when you have explicit parameters on your action method – allowing you to cleanly enable output caching on actions using code like below:

image

In addition to supporting full page output caching, ASP.NET MVC 3 also supports partial-page caching – which allows you to cache a region of output and re-use it across multiple requests or controllers.  The [OutputCache] behavior for partial-page caching was updated with RC2 so that sub-content cached entries are varied based on input parameters as opposed to the URL structure of the top-level request – which makes caching scenarios both easier and more powerful than the behavior in the previous RC.

@model declaration does not add whitespace

In earlier previews, the strongly-typed @model declaration at the top of a Razor view added a blank line to the rendered HTML output. This has been fixed so that the declaration does not introduce whitespace.

Changed "Html.ValidationMessage" Method to Display the First Useful Error Message

The behavior of the Html.ValidationMessage() helper was updated to show the first useful error message instead of simply displaying the first error.

During model binding, the ModelState dictionary can be populated from multiple sources with error messages about the property, including from the model itself (if it implements IValidatableObject), from validation attributes applied to the property, and from exceptions thrown while the property is being accessed.

When the Html.ValidationMessage() method displays a validation message, it now skips model-state entries that include an exception, because these are generally not intended for the end user. Instead, the method looks for the first validation message that is not associated with an exception and displays that message. If no such message is found, it defaults to a generic error message that is associated with the first exception.

RemoteAttribute “Fields” -> “AdditionalFields”

ASP.NET MVC 3 includes built-in remote validation support with its validation infrastructure.  This means that the client-side validation script library used by ASP.NET MVC 3 can automatically call back to controllers you expose on the server to determine whether an input element is indeed valid as the user is editing the form (allowing you to provide real-time validation updates).

You can accomplish this by decorating a model/viewmodel property with a [Remote] attribute that specifies the controller/action that should be invoked to remotely validate it.  With the RC this attribute had a “Fields” property that could be used to specify additional input elements that should be sent from the client to the server to help with the validation logic.  To improve the clarity of what this property does we have renamed it to “AdditionalFields” with today’s RC2 release.

ViewResult.Model and ViewResult.ViewBag Properties

The ViewResult class now exposes both a “Model” and “ViewBag” property off of it.  This makes it easier to unit test Controllers that return views, and avoids you having to access the Model via the ViewResult.ViewData.Model property.

Installation Notes

You can download and install the ASP.NET MVC 3 RC2 build here.  It can be installed on top of the previous ASP.NET MVC 3 RC release (it should just replace the bits as part of its setup).

The one component that will not be updated by the above setup (if you already have it installed) is the NuGet Package Manager.  If you already have NuGet installed, please go to the Visual Studio Extensions Manager (via the Tools –> Extensions menu option) and click on the “Updates” tab.  You should see NuGet listed there – please click the “Update” button next to it to have VS update the extension to today’s release.

If you do not have NuGet installed (and did not install the ASP.NET MVC RC build), then NuGet will be installed as part of your ASP.NET MVC 3 setup, and you do not need to take any additional steps to make it work.

Summary

We are really close to the final ASP.NET MVC 3 release, and will deliver the final “RTM” build of it next month.  It has been only a little over 7 months since ASP.NET MVC 2 shipped, and I’m pretty amazed by the huge number of new features, improvements, and refinements that the team has been able to add with this release (Razor, Unobtrusive JavaScript, NuGet, Dependency Injection, Output Caching, and a lot, lot more).  I’ll be doing a number of blog posts over the next few weeks talking about many of them in more depth.

Hope this helps,

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Published Friday, December 10, 2010 11:47 PM by ScottGu
Filed under: , , ,

Comments

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 2:52 AM by Todd Lucas

Looking forward to it. I love what you're doing with MVC and the platform in general.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 2:55 AM by wayne-o

We're building our new app based on Razor and love it so far - great work guys :)

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:03 AM by hajan

I'm eager to try all the new features now! I like all the new features in this RC 2, especially the ViewBag and the improvements in output caching.

Thank you!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:18 AM by Israr Khan

Like it more and more ;)

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:30 AM by Bats Ihor

Thank, Now i will try to update me project. I hope it will work )

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:43 AM by Naga Harish

Nice, thanks you for sharing :)

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:49 AM by sohelelite

finally trusted stamp by ScottGu will help me to use Asp.net MVC 3 in my real world application hope this will fulfill all my requirement

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 4:01 AM by Guillaume

Great work guys...

Nothing about a new modern authentication module for asp.net mvc ? for me, it is the big missing !

Do you plan to do something on that subject ?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 4:05 AM by kouphax

Hmmmm after instaing RC2 over RC1 the project template hasn't changed - I still get ViewModel instead of ViewBag (though it flags this as an error) and no jQueryUI.  Going to do a clean install to see if that helps.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 4:13 AM by Martin

Why do you bundle NuGet with RC2?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 4:41 AM by kouphax

Yes that has fixed the issue.  Now my one minor gripe.  The (partial) inclusion of jQuery UI.  It's missing the base CSS library required for jQueryUI.  Makes the whole inclusion a bit pointless as you then have to go fetch it.  Also it's the "full" build.  If I wanted to simply add a slider to my page I would typically just add the base JS file and the Slider file.  Including the whole framework is simply overkill IMHO.  It's a nice idea but not properly executed - to be honest NuGet would be a much neater solution for this.

Other than that - everything is, as always excellent.  Keep up the excellent work.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 5:20 AM by Daniel Steigerwald

As usual, nice improvements, thank u.

One question, where I can find docs or even source code? I would like to write own client validation based on Google Closure library, so I need to see which data-val- attributes are supported for example.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 5:43 AM by rekna

I've posted a bug I encounter with MVC3 RC2 on ASP.NET forums (forums.asp.net/.../1632006.aspx).It seems that when a controller method contains a nullable int as parameter, this parameter is always null even when the request params contain a value for this parameter.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 6:07 AM by Jón Trausti

Congratulations on the rc, it is great to see all the performance improvements.

I have one question about long polling (comet). Are there any plans by the MVC or asp.net team to make some features for that?

My main concern is that most people seem to be afraid of comet due to how expensive it can be, assigning one thread per request and making it wait for data.

Thanks.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 6:46 AM by Alvipeo

Our two next project will be done with MVC3 and Razor! Great framework, thank you guys!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 8:00 AM by Giarico

Will MVC3 work with IIS 5.1 & IIS 6? It's very important for me!!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 8:04 AM by chad smith

ViewBag. Ha! I bet your devs had a good laugh with this one. Great work, looking forward to updating from mvc2 to mvc3 (with Razor - I love the simplicity & control of html with dev just sticking in the variables, a continued frustration of mine with web forms & server controls).

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 9:40 AM by qanuj

Love what you do. Its been great to see MVC team doing great job in such a short time.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 11:31 AM by Simon Rigby

Great work guys. Rebuilding my company site using MVC3 and loving the Razor syntax

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 11:31 AM by Simon Rigby

Great work guys. Rebuilding my company site using MVC3 and loving the Razor syntax

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 11:32 AM by panrobal

I am experiencing same problem as rekna. All the models with nullable ints crashed - I get model validation errors and other errors related to this issue.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 12:27 PM by Will

I can't get this to install into 2010SP1beta (previous MVC RC was fine, and NuGet update via extension manager was fine.)

To whom should I go for help, or should I just start reinstalling everything?

Here's a little sample of the log from around the the Aaron Stebner 'search for 'return value 3'' rule applied:

---------

MSI (s) (40:B4) [17:12:06:298]: Executing op: AssemblyCopy(SourceName=103458|Microsoft.shdocvw.dll,SourceCabKey=FL_Interop_SHDocVw_dll_103458_103458_x86_ln.3643236F_FC70_11D3_A536_0090278A1BB8,DestName=Microsoft.shdocvw.dll,Attributes=16896,FileSize=141152,PerTick=65536,,VerifyMedia=1,,,,,ComponentId={26B4CC4A-806C-4BCF-86BB-DB07AB98D5FB},IsManifest=1,,,AssemblyMode=0,)

DEBUG: Error 2902:  Operation ixfAssemblyCopy called out of sequence.

MSI (s) (40:B4) [17:12:06:304]: Product: Microsoft Visual Studio 2010 Ultimate - ENU -- The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2902. The arguments are: ixfAssemblyCopy, ,

The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2902. The arguments are: ixfAssemblyCopy, ,

The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2902. The arguments are: ixfAssemblyCopy, ,

MSI (s) (40:B4) [17:12:06:307]: User policy value 'DisableRollback' is 0

MSI (s) (40:B4) [17:12:06:307]: Machine policy value 'DisableRollback' is 0

Action ended 17:12:06: InstallFinalize. Return value 3.

---------

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 1:41 PM by Konstantin

We are building a system with MVC3 and I wanted to thank you guys for your work. It's a pleasure to work with this stack!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 2:25 PM by Ericpoon

When I using MVC3 with strongly-typed view, I try to create a view<Product> and pass a IList<Product> like " return view(productList)". The compiler cannot find out the wrong type I passed in my controller in compile time. So why MS provided the Strongly-Type View?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 2:40 PM by cs

I'm having some trouble understanding why one would use a ViewBag and have to pay the late binding tax instead of creating a model object containing this data.

For example:

public class ProductViewData {

 public string Message { get; set; }

 public Product Product { get; set; }

 public List<string> Categories { get; set; }

}

Can you clarify? Thanks!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:25 PM by ScottGu

@Guillaume

>>>>>>> Nothing about a new modern authentication module for asp.net mvc ? for me, it is the big missing ! Do you plan to do something on that subject ?

We won't have any new authentication systems built-into ASP.NET MVC 3.  But you can install other auth schemes (like OpenID) using the NuGet package manager.  I expect you'll see a lot of extensions (including for auth) show up there shortly.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:28 PM by ScottGu

@Martin,

>>>>>>> Why do you bundle NuGet with RC2?

One of the things we are trying to do with NuGet is to provide a standard package management system that enables developers to easily find and install free and open source .NET extensions and libraries.  Having NuGet installed by default makes it easier for developers to get started with it, and in turn hopefully causes even more libraries to be built (since the addressable audience is even bigger).

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:29 PM by ScottGu

@kouphax

>>>>> Now my one minor gripe.  The (partial) inclusion of jQuery UI.  It's missing the base CSS library required for jQueryUI.  Makes the whole inclusion a bit pointless as you then have to go fetch it.  Also it's the "full" build.  If I wanted to simply add a slider to my page I would typically just add the base JS file and the Slider file.

Thanks for pointing out the base CSS library issue. I'll follow up with the team on this.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:33 PM by ScottGu

@Daniel Steigerwald

>>>>>>> One question, where I can find docs or even source code? I would like to write own client validation based on Google Closure library, so I need to see which data-val- attributes are supported for example.

We are still working furiously on documentation - we should have a lot in place by the final RTM, but right now mostly it is available via blogs, forums, etc (since the information is being developed in real-time).  The source code for MVC will also be out by RTM (and under an OSI open-source license).

To learn more about how to build your own Javascript client library for validation, I'd recommend checking out Brad Wilson's post here: bradwilson.typepad.com/.../mvc3-unobtrusive-validation.html

He also has a number of other great posts about validation and asp.net on his site.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:36 PM by ScottGu

@rekna, @panrobal

>>>>>> I've posted a bug I encounter with MVC3 RC2 on ASP.NET forums (forums.asp.net/.../1632006.aspx).It seems that when a controller method contains a nullable int as parameter, this parameter is always null even when the request params contain a value for this parameter.

Thanks for reporting this - we are going to take a look at it right away.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:37 PM by ScottGu

@Jón Trausti,

>>>> I have one question about long polling (comet). Are there any plans by the MVC or asp.net team to make some features for that?  My main concern is that most people seem to be afraid of comet due to how expensive it can be, assigning one thread per request and making it wait for data.

This is an area we are looking at now.  There are a few issues related to perf, and more recently related to security with websockets, that we are investigating.  I expect we'll have some degree of built-in support for it in the future.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:38 PM by ScottGu

@Giarico

>>>>>> Will MVC3 work with IIS 5.1 & IIS 6? It's very important for me!!

Yes - that is fully supported with ASP.NET MVC 3.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:40 PM by ScottGu

@Will,

>>>>>>> I can't get this to install into 2010SP1beta (previous MVC RC was fine, and NuGet update via extension manager was fine.) To whom should I go for help, or should I just start reinstalling everything?

Sorry you are running into this.  Can you send me email (scottgu@microsoft.com) and we'll help figure out what is going wrong.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:41 PM by ScottGu

@Ericpoon

>>>>>>> When I using MVC3 with strongly-typed view, I try to create a view<Product> and pass a IList<Product> like " return view(productList)". The compiler cannot find out the wrong type I passed in my controller in compile time. So why MS provided the Strongly-Type View?

Can you provide more details on exactly what your Controller looks like and what the View template looks like?

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 3:46 PM by ScottGu

@cs,

>>>>>> I'm having some trouble understanding why one would use a ViewBag and have to pay the late binding tax instead of creating a model object containing this data. For example:

>>>>>> public class ProductViewData {

>>>>>>    public string Message { get; set; }

>>>>>>    public Product Product { get; set; }

>>>>>>    public List<string> Categories { get; set; }

>>>>>> }

>>>>>>  Can you clarify? Thanks!

Both are valid options, and generally it comes down to one of programmer preference.  One benefit of a viewmodel class like above is that it is strongly-typed - and so you'll get full intellisense and compile checking for it.  You are also effectively defining a contract between your Controller and View, and this contract can be different than your underlying data model classes (which means your views are less dependent on your data store/schema).  From a pure architecture perspective this is a clean thing to do.

The downside with a strongly-typed viewmodel, though, is that sometimes you aren't passing much more than the underlying domain model object to your view - and so creating a ViewModel class that only has one or two properties can feel like overkill.  A late-bound collection like ViewBag makes it easy to pass these extra pieces of data to your view without requiring you to create new classes.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 4:48 PM by Ericpoon

Model:

   public class Product

   {

       public int ProductId { get; set; }

       public string ProductName { get; set; }

   }

View ShowProds.aspx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Product>" %>

<html>

<head></head>

<body>

           <p>

               <%=Html.TextBoxFor<Product,int>(c=>c.ProductId) %>

           </p>

           <p>

               <%=Html.TextBoxFor<Product,string>(c=>c.ProductName) %>

           </p>

</body>

</html>

HomeController:

   public class HomeController : Controller

   {

       //

       // GET: /Home/

       public ActionResult Index()

       {

           return View();

       }

       public ActionResult ShowProds()

       {

           Product p =new Product{ ProductId=1,ProductName="abc"};

           IList<Product> list = new List<Product>();

           list.Add(new Product { ProductId = 1, ProductName = "abc" });

           list.Add(new Product { ProductId = 2, ProductName = "bc" });

           //return View(p);  // this line is match the strongly-type View

           return View(list); // this not match, but no compile time errors or warnings.

       }

}

Why MVC strongly-type View does not have compile time errors?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 4:53 PM by @scottcate

Check out the Gu on support! This is awesome. I've seen @Haacked, @SHanselman, and @ScottGu all talking to customers 1-on-1 about the release of MVC3 RC2. Where else do you see the produce team this open to customer interaction?

Love it, good job guys.

@ScottCate

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 6:44 PM by duganzhang

The Razor view seems always compile in debug mode even when <compilation debug="false"> is set in the web.config. Will this be fixed by the time RTM?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 9:51 PM by 曾祥展

不错  MVC3的RC版本似乎更接近Beta的效率,效率差别比较明显(尤其是对Razor的优化)

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 10:02 PM by jemiller

I'm wondering why the source code downloads are lagging behind the binary downloads? Why don't you release them both at the same time? For example, on CodePlex, the source code download is for Beta 2. And if you download the source using Subversion, things are missing. For example the webpages directory. I commend you for making the project open source, but, I think you need to do better at making the source code available also when you release new binaries.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 11, 2010 11:10 PM by jemiller

@Scott

Are you sure the installer doesn't also update NuGet if you had MVC 3 RC installed before installing RC2? I installed RC2 without first uninstalling RC. After I installed it, I went into Extensions Manager and the Date Installed says todays date with a version number of 1.0.10128.89. If I go under Updates, it says No items found. Oddly, NuGet is listed with version number 1.0.11209.0 under Programs and Features in the Control Panel. The is the same version number as the rest of the MVC 3 components. So, it looks like it upgrades it automatically.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 4:40 AM by Beyers

Great stuff Scott and team, loving it.

@Scott

Can you please add the MVC tag to this post? Your blog is one of the few that I actually use the tags feature.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 5:43 AM by Vladimir

Hi, Scott.

There is description of new AdditionalMetadataAttribute in release notes (missed in your post, btw).

Can you provide an example with it? Maybe I don't understand something, but I can't get any values form ModelMetadata.AdditionalValues in runtime. It's always empty. So is there a bug or something wrong?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 9:04 AM by Bart

There is a problem using _ViewStart in an Area and running aspnet_merge.exe (windows sdk 7.1), this also occurred in RC1.

aspnet_merge : error occurred: An error occurred when merging assemblies: ILMerge.Merge: ERROR!!: Duplicate type 'ASP._ViewStart_cshtml' found in assembly 'App_Web_20msfnbh'

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 11:41 AM by rekna

Concerning the bug I posted (ASP.NET forums (forums.asp.net/.../1632006.aspx)) with the nullable int parameter, this has been confirmed to be a bug introduced in RC2 and in the same post is mentioned a workaround that solves the problem for now

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 7:07 PM by Deep

Its great news that there wont be any code changes or major changes from RC 2 to final release. Wondering that where can i find tutorials and examples regarding Unobtrusive JavaScript and model level validation. I have started building an app using MVC 3 RC and finding it hard to find any hosts supporting it but i guess that should change when final release comes out in January 2011

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 7:27 PM by IgoKu

Can I use DefaultModelBinder using attribute AllowHtml or need a custom modelbinder?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 9:15 PM by Michael Stum

Out of interest, since jQuery UI has many themes, which one is bundled with MVC3?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 9:49 PM by MartinF

Hello Scott,

files created seems to have the identation specified/hardcoded instead of adjusting to the current visual studio settings.

This means that I have to reformat the identation of every file I create (relating to MVC) as I dont have Tab size set to 4 spaces, but only 3.

It works fine when creating class, interface files (etc.), but any of the files relating to Mvc seems to have it hardcoded and needs to be reformated.

It is pretty annoying.

Martin

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 12, 2010 10:40 PM by Riza Marhaban

Nice!!! great work guys...

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 2:52 AM by Jonathan Allen

Unfortunately it isn't installing for me either.

Exe (c:\temp\ext6142\VS10-KB2465236-x86.exe) failed with 0x80070643 - Fatal error during installation. .

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 2:57 AM by ScottGu

@EpicPoon,

Your view is expecting a Product - but you are passing a list of products to your view.  Try changing the top declaration to instead be:

  <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcApplication1.Models.Product>>" %>

That will then match what is being passed.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:04 AM by ScottGu

@jemiller

>>>>> I'm wondering why the source code downloads are lagging behind the binary downloads? Why don't you release them both at the same time? For example, on CodePlex, the source code download is for Beta 2. And if you download the source using Subversion, things are missing. For example the webpages directory. I commend you for making the project open source, but, I think you need to do better at making the source code available also when you release new binaries.

We are working on getting the source posted now.  We will also make sure it is live when we RTM.

Sorry for the delay,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:05 AM by ScottGu

@jemiller

>>>>>>> Are you sure the installer doesn't also update NuGet if you had MVC 3 RC installed before installing RC2? I installed RC2 without first uninstalling RC. After I installed it, I went into Extensions Manager and the Date Installed says todays date with a version number of 1.0.10128.89. If I go under Updates, it says No items found. Oddly, NuGet is listed with version number 1.0.11209.0 under Programs and Features in the Control Panel. The is the same version number as the rest of the MVC 3 components. So, it looks like it upgrades it automatically.

If it worked then that is goodness :-)  I ran into a situation on my machine where it didn't - which is why I called it out as something to check.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:11 AM by ScottGu

@Bevers,

>>>>>>> Can you please add the MVC tag to this post? Your blog is one of the few that I actually use the tags feature.

Done!

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:13 AM by ScottGu

@Vladimir,

>>>>>> There is description of new AdditionalMetadataAttribute in release notes (missed in your post, btw). Can you provide an example with it? Maybe I don't understand something, but I can't get any values form ModelMetadata.AdditionalValues in runtime. It's always empty. So is there a bug or something wrong?

I have to confess I've not used it before myself :-)  Can you try asking this question in the MVC forum: forums.asp.net/1146.aspx

Someone from the team will be able to help provide an example!

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:14 AM by ScottGu

@Bart,

>>>>>>> There is a problem using _ViewStart in an Area and running aspnet_merge.exe (windows sdk 7.1), this also occurred in RC1. aspnet_merge : error occurred: An error occurred when merging assemblies: ILMerge.Merge: ERROR!!: Duplicate type 'ASP._ViewStart_cshtml' found in assembly 'App_Web_20msfnbh'

Thanks for posting about this - I just forwarded it to the team to see if it is a known issue.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:24 AM by ScottGu

@Victor,

>>>>>>> In the meantime I moved to VS 2010 Professional, MVC 2 comes part of .NET Framework 4, so I said great, will use MVC 2 for my first web app with VS 2010. At some point, VS suggested I install something (don't remember what it was and cannot find it in Control Panel) to make intellisense or autocomplete run faster - I did that yesterday it was some MS KB package. Today, while trying to edit a View page markup/code, VS 2010 keeps crashing on me.

Can you send me an email (scottgu@microsoft.com) with more details about the issue?  As part of that can you also use the Help->About menu command in VS and click the "Copy Info" button and paste the results in the email you send?  This will allow us to see what extensions you have installed.

>>>>>>>> I think MVC 3 is too fresh to be trusted for a production app. My question is what would you do in my place? Keep going with MVC 2 and risk wasting more time or tiptoe your way through / take a deep breath and dive into MVC 3 / dump it all and roll my own?

For new projects I'd recommend going with MVC 3.  It supports all of the MVC 2 features, but also brings a lot more capabilities and improvements to the table.  The performance and quality of it is also now really good.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:25 AM by ScottGu

@Deep,

>>>>>>> Its great news that there wont be any code changes or major changes from RC 2 to final release. Wondering that where can i find tutorials and examples regarding Unobtrusive JavaScript and model level validation. I have started building an app using MVC 3 RC and finding it hard to find any hosts supporting it but i guess that should change when final release comes out in January 2011

We'll have a lot more tutorials coming out shortly that go into depth on all the new features.  In the meantime I'd recommend checking out Brad's post here: bradwilson.typepad.com/.../mvc3-unobtrusive-ajax.html

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:26 AM by ScottGu

@IgoKu

>>>>>> Can I use DefaultModelBinder using attribute AllowHtml or need a custom modelbinder?

Yes - this should work fine out of the box using the DefaultModelBinder.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:27 AM by ScottGu

@Michael,

>>>>>>> Out of interest, since jQuery UI has many themes, which one is bundled with MVC3?

With the RC2 build I don't think any theme is currently bundled.  I just sent mail asking if maybe we should include one though.

Thanks for pointing that out,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:28 AM by ScottGu

@MartinF,

>>>>>>>> files created seems to have the identation specified/hardcoded instead of adjusting to the current visual studio settings.

I just forwarded this to the team to look at.  I'm not sure we've ever supported customizing this within non-class item templates before - but we'll take a look to figure out what is going on.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 3:29 AM by ScottGu

@Jonathan Allen,

>>>>>>> Unfortunately it isn't installing for me either. Exe (c:\temp\ext6142\VS10-KB2465236-x86.exe) failed with 0x80070643 - Fatal error during installation. .

Can you try downloading it again and re-running setup?  That error looks a lot like a file corruption issue with the setup.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 4:30 AM by nick_uk

I am also getting that error as well.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 5:53 AM by IgoKu

Scott, my first question about the AllowHtml attribute has been set for a reason... The fact is that, unlike the good old ;-) SkipRequestVerification who normally worked in the RC (with DefaultModelBinder), AllowHtml presented in RC2 is not working... and I recieve known message "A potentially dangerous Request.Form value was detected from the client...".

May be this is just a bug?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 7:48 AM by Morten Ludvigsen

I was playing around with unobtrusive ajax, and it looks very good. Much easier than doing ajax by hand in jQuery. I do have a problem though. In the standard MVC application I have added the following Action to the Home Controller:

 public string GetTime()

 {

   return DateTime.Now.ToString("O");

 }

In Index.cshtml I have added:

 @Ajax.ActionLink("Get time", "GetTime",

     new AjaxOptions { HttpMethod = "get",

                       UpdateTargetId = "ShowTime",

                       InsertionMode = InsertionMode.Replace })

 <div id="ShowTime">

   Initial value: @{ Html.RenderAction("GetTime"); }

 </div>

Now, every time I press the "Get time" link I should see a new value in the "ShowTime" div. This works perfectly in Firefox, but only the first time I press the link in IE 8. Subsequent attempts do not change the value in the "ShowTime" div - until I refresh the entire page.

This might be something you would like to look into before the "RTM" build.

Hope you can use this :-)

Kind regards,

Morten

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 8:16 AM by jarda

I am getting the

"The resource cannot be found."

Requested URL: /Product/Account/Login

error again after upgrading from RC1 to RC2. In RC1 this was fixed by adding the following line to the web.config:

<add key="AutoFormsAuthentication" value="false" />

Any idea what might be causing it now?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 8:43 AM by JeffBue

Installation fails with VS 2010 SP1 Beta and MVC3 RC1.

[12/13/2010, 7:32:55]Exe (e:\temp\ext6142\VS10-KB2465236-x86.exe) failed with 0x80070643 - Fatal error during installation. .

[12/13/2010, 7:32:55]PerformOperation on exe returned exit code 1603 (translates to HRESULT = 0x80070643)

[12/13/2010, 7:32:55] Action complete

[12/13/2010, 7:32:55]Error 1603 is mapped to Custom Error:

[12/13/2010, 7:32:55]OnFailureBehavior for this item is to Rollback.

[12/13/2010, 7:32:55] Action complete

[12/13/2010, 7:32:55]Final Result: Installation failed with error code: (0x80070643), "Fatal error during installation. " (Elapsed time: 0 00:00:20).

Regards,

Jeff

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 9:10 AM by counsellorben

Showstopper!

Unobtrusive validation still is not being emitted for dropdownlists.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 10:55 AM by Mario

Is the new partial caching (renderaction) extensible?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 11:02 AM by lokaty

'Our latest performance tests indicate that ASP.NET MVC 3 is now faster than ASP.NET MVC 2, and that existing ASP.NET MVC applications will experience a slight performance increase when updated to run using ASP.NET MVC 3.'

It's good news for everybody. I'm looking forward to your new ASP.NET MVC 3!

Best regards,

L

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 11:52 AM by Rohland

Hi Scott,

There seems to be a funky bug with the Razor View Engine when using conditional logic. Try this:

@if (Model == null)

{

 <span>null</span>

}

vs. this

@if (Model == null)

{

   <span>null</span> some text outside the span

}

The second case doesn't work and causes a compilation failure when the view is rendered.

Fully aware that I may be using Razor incorrectly, but it doesn't seem intuitive that the first case would work but not the second. Bug?

Cheers,

Rohland

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 1:40 PM by jemiller

I was just looking at the CompareAttribute and noticing that it needs improvement. I'm wondering if it will be extended to include the functionality in <asp:CompareValidator/> in ASP.NET Web Forms? At present, it only does an exact comparison. It would be great if it were made so that you could specify an operator so that you could use it for things like date comparisons like end date has to be greater than start date.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 2:11 PM by jemiller

It looks like there is still some fit and finish work that needs to be done. One thing that I'm wondering is why fields that have an [Editable(false)] attribute are added to the template for Edit pages? Another thing is why don't the list pages use the Grid HTML helper? Another thing that would be nice is if the default labels would add spaces to property names that have capital letters in them by default. For example, if I have a property named ReplacementCost, it would be nice if the default label was "Replacement Cost." If I remember correctly, the Silverlight DataGrid does this.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 4:34 PM by Peter

Hi Scott,

Why do statements in a Razor template like this:

@if(condition) {

<span>test</pan>

}

Cause empty lines in the HTML source where the code syntax is?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 6:01 PM by Martin Booth

@jemiller

The code for the compare validator is very simple.. its probably not even worth the framework providing other comparison validators, and instead lets the compareattribute serve as an example.. take a look at the source and you'll see its only about 20 lines long

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 6:24 PM by MartinF

Hello Scott,

thanks, hope you understand what I mean, as i couldnt seem to find the right words.

I also noticed that there is no indication that code in a Razor view is not valid.

Normally the invalid code is marked with a different color (usually red).

Is it an error ? or will this come later ?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 13, 2010 6:24 PM by MartinF

Hello Scott,

thanks, hope you understand what I mean, as i couldnt seem to find the right words.

I also noticed that there is no indication that code in a Razor view is not valid.

Normally the invalid code is marked with a different color (usually red).

Is it an error ? or will this come later ?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 2:08 AM by ScottGu

@IgoKu

>>>>>> Scott, my first question about the AllowHtml attribute has been set for a reason... The fact is that, unlike the good old ;-) SkipRequestVerification who normally worked in the RC (with DefaultModelBinder), AllowHtml presented in RC2 is not working... and I recieve known message "A potentially dangerous Request.Form value was detected from the client...".

Unfortunately we found an issue with the RC2 bits that causes something to be cached too aggressively and to cause this to fail.

You can fix this by adding the following line of code to the Application_Start() event handler within your Global.asax:

ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();

It should then work fine.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 4:56 AM by ashic

Hi Scott,

RC2 looks good...thanks for adding jquery UI out of the  box. One thing though...please please rename ViewBag. It just sounds wrong. I can see two possible alternatives:

1. Call it "ViewData" in both the controller and the view. This does add some typing in the View code.

2. Just call it "Data". It conveys all the intent in both the controller and the view. And it is just four characters. And it sounds (and looks) a hell of a lot better than View, ViewData, ViewModel, ViewBag, ViewPurse etc.

I know it's late but if it can change between RC1 and RC2, surely it can change in RTM...I mean once it hits RTM, we all get stuck with ViewBag for all eternity.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 5:43 AM by Jovan Paskota

@Jonathan Allen,

Regarding the installation, had the same problem, unpacked the install file and installed piece by piece. When running vs10-kb2465236-x86.exe it asked for the setupdisk of visual studio. After i provided it with the setup source averything installed correctly.

/Jovan

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 8:12 AM by Jack Jackson

@Scott

What the heck is a ViewBag? Why have ViewData and ViewBag do the same thing?

Why not just make ViewData dynamic. It's not like VB style late binding, it just works the same as a dictionary behind the scenes doesn't it?

ViewBag, bad move guys.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 12:15 PM by IgoKu

Thank you, Scott.

Now AllowHtml attribute works as expected.

As I understand this solution is temporary, and after recieving RTM of MVC 3 we can drop this line in global.asax? Anyway this is not a big problem.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 12:52 PM by ScottGu

@Morten Ludvigsen

>>>>>> I was playing around with unobtrusive ajax, and it looks very good. Much easier than doing ajax by hand in jQuery. I do have a problem though. In the standard MVC application I have added the following Action to the Home Controller.

The problem you are running into is because you are using an HTTP-GET for your Ajax call instead of HTTP-POST.  Browsers will cache HTTP-GET requests by default if the URLs match (which they do in this case).  If you change it to POST it should work.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 12:53 PM by ScottGu

@JeffBue,

>>>>>> Installation fails with VS 2010 SP1 Beta and MVC3 RC1.

Can you send me email (scottgu@microsoft.com) about this?  I can then follow-up and help.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 12:57 PM by ScottGu

@Rohland

>>>>> There seems to be a funky bug with the Razor View Engine when using conditional logic. Try this:

>>>>> @if (Model == null)

>>>>> {

>>>>>    <span>null</span> some text outside the span

>>>>> }

This is actually by design.  I'm planning on doing a blog post about this shortly to explain it more.

To indicate that the entire line should be treated as a text literal do this:

@if (Model == null)

{

  @:<span>null</span> some text outside the span

}

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 12:58 PM by ScottGu

@counsellorben

>>>>>>>> Unobtrusive validation still is not being emitted for dropdownlists.

Can you send me email (scottgu@microsoft.com) with more information about this?

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 1:30 PM by ScottGu

@Peter,

>>>>>> Why do statements in a Razor template like this:

>>>>>> @if(condition) {

>>>>>>   <span>test</pan>

>>>>>>}

>>>>>> Cause empty lines in the HTML source where the code syntax is?

We just tried this out in a few machines and couldn't repro the problem.  If you have this:

BEFORE

@if(false) {

   <span>test</span>

}

AFTER

It generates the following output:

BEFORE

AFTER

Can you send me an email (scottgu@microsoft.com) with more details to explain what you are seeing instead?

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 1:34 PM by ScottGu

@Mario

>>>>>>>>> Is the new partial caching (renderaction) extensible?

We expose a static OutputCacheAttribute.ChildActionCache property (typed as ObjectCache) with a public getter / setter.  You can make an ObjectCache-derived type, then just set the static cache to be an instance of that type, and child action caching will honor it.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 2:03 PM by ScottGu

@ashic,

>>>>>>> RC2 looks good...thanks for adding jquery UI out of the  box. One thing though...please please rename ViewBag. It just sounds wrong. I can see two possible alternatives:

>>>>>>> 1. Call it "ViewData" in both the controller and the view. This does add some typing in the View code.

Unfortunately renaming the existing ViewData property to be dynamic is not possible as it breaks a few scenarios.  We didn't want to make this broad a breaking change.

>>>>>>> 2. Just call it "Data". It conveys all the intent in both the controller and the view. And it is just four characters. And it sounds (and looks) a hell of a lot better than View, ViewData, ViewModel, ViewBag, ViewPurse etc.

Naming this particular property has been tricky and a long debate internally on the team.  We tried to have something that made it clear as to the use.  we thought having "View" in the name makes it clear that it is related to View, and Bag indicates that is a late-bound collection of "stuff" - which is what it is.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 2:16 PM by ScottGu

@IgoKu

>>>>>>> Now AllowHtml attribute works as expected.  As I understand this solution is temporary, and after recieving RTM of MVC 3 we can drop this line in global.asax? Anyway this is not a big problem.

Yes - we'll have this fixed for RTM.  The above step is just a workaround.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 2:21 PM by ScottGu

@Jack Jackson,

>>>>>>> Why not just make ViewData dynamic. It's not like VB style late binding, it just works the same as a dictionary behind the scenes doesn't it?

Unfortunately renaming the existing ViewData property to be dynamic is not possible as it breaks a few scenarios with existing code.  We didn't want to make this broad a breaking change.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 2:35 PM by jbatte

Hi Scott,  I've enjoyed working with Razor so far, but I have run into a problem that I don't quite understand.  Now that I have installed RC2, when I create a new Razor application and run it, the global.asax immediately breaks with a Parser error.  The message is Could not load type 'Your.Namespace.Here.MvcApplication'".  The type name corresponds correctly with the contents of the global.asax.cs file, and the project is building successfully.  I checked the fusion log just to be sure, and there are no failed bindings.  I'm out of ideas; hopefully you'll be able to enlighten me!

Thanks

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 2:59 PM by ScottGu

@jbatte,

>>>>>>>> I've enjoyed working with Razor so far, but I have run into a problem that I don't quite understand.  Now that I have installed RC2, when I create a new Razor application and run it, the global.asax immediately breaks with a Parser error.  The message is Could not load type 'Your.Namespace.Here.MvcApplication'".  The type name corresponds correctly with the contents of the global.asax.cs file, and the project is building successfully.  I checked the fusion log just to be sure, and there are no failed bindings.  I'm out of ideas; hopefully you'll be able to enlighten me!

Can you send me an email (scottgu@microsoft.com) with details of the issue and I can connect you with someone to help?

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 3:05 PM by ScottGu

@duganzhang,

>>>>>>>> The Razor view seems always compile in debug mode even when <compilation debug="false"> is set in the web.config. Will this be fixed by the time RTM?

Razor does compile with debug on by default.  We've found in perf testing that this doesn't slow anything down, while at the same time dramatically improving the quality of error messages.  That is why we've gone with that always on by default.

Hope this helps,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 3:06 PM by ScottGu

@jarda

>>>>>>> I am getting the "The resource cannot be found." Requested URL: /Product/Account/Login error again after upgrading from RC1 to RC2. In RC1 this was fixed by adding the following line to the web.config:

>>>>>>> <add key="AutoFormsAuthentication" value="false" />

>>>>>>> Any idea what might be causing it now?

You shouldn't be seeing this.  Do you have some old WebMatrix DLL assembly references in your project?  That is one thing that might cause it (and could be related to having some old bits on your system).

Send me an email (scottgu@microsoft.com) if you don't see these references and we can help further.

Thanks,

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 3:49 PM by sn

@scott: in my simple hello world applications with razor templating, there is 2 times performance difference with debug and release modes (compilation in release + debug=false in web.config).

thanks,

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 14, 2010 4:21 PM by Randy

Awesome work!  Looking forward to updating our code so we can use the new features!!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 8:23 AM by jgauffin

I also had problems with installing RC3.

1. Tried to install RC2 [failed]

2. Tried to uninstall webpages and MVC3 RC1 and then install RC2 [failed]

3. Tried to uninstall webpages, RC1, reboot and then install RC2 [success]

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 8:36 AM by jgauffin

@Jovan Paskota:

You shouldn't do that in your views at all. All logic should be in the controllers. Instead you should provide the path to the script as part of the ViewBag.

For instance, you could override OnResultExecuting in your basecontroller to provide the path.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 1:15 PM by Martin

The ViewBag is great, but why isn't the TempData dictionary also dynamic? Would be awesome.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 2:42 PM by Diego

My installatio of ASP.NET MVC RC2 has been running for more than 40 minutes now, it is progressing but it's ridiculously slow. You seriously have to fix this installer, it's taking more time to install 8 dlls than installing Crysis and Starcraft 2 combined

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 4:20 PM by Josh

Any plans for slipping a TempBag into mvc3? It'd be nice to have the same dynamic style to replace TempData as ViewBag replaces ViewData.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 7:40 PM by Yasen

Great stuff!

I've been playing around a bit and bumped into a strange issue. Whenever I load html from an ajax call, I cannot get the unobtrusive validation to work. This happens when the content comes from an action returning PartialViewResult (I've tried jQuery.load() and jQuery.ajax() with post and get methods). When I do that, none of the data-val-* attributes are generated. jQuery.validator.unobtrusive.parse() is searching for those attributes and when they are not available, no validation occurs on the generated content. However, when calling the Partial View through Html.RenderPartial(), everything turns out to be OK, but this is not the solution when you want to make ajax calls to render content, right? What am I doing wrong? I'm using my own Metadata provider for some custom attributes - could this be causing the issue?

Thanks!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 15, 2010 8:16 PM by jemiller

@Martin Booth

The point is that a robust CompareAttribute is something that should come standard with MVC, just like there is CompareValidator with Web Forms. I know MVC isn't very mature, but, it's something that needs to be there if people are expected to move from Web Forms to MVC. I would like to see MVC match Web Forms in terms of functionality. It isn't there yet. The Grid needs a lot of improvement also. My guess is that it's going to be about MVC 5 before it catches up to Web Forms in terms of controls (or helpers in MVC parlance).

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Thursday, December 16, 2010 3:28 PM by Michael Stokesbary

Hey Scott -

Long time listener, first time caller. Just wanted to make a mention here that when upgrading from RC1 to RC2, if someone was trying to get an existing RC1 project working with the RC2 bits, they will want to update the javascript files in their existing RC1 project. I found this out the hard way after pulling out most of my hair when my AdditionalFields property on my Remote attribute call stopped passing the fields (got the compilation error saying that Fields wasn't valid anymore, so knew I had to make the change to AdditionalFields, but couldn't figure out why the parameter wasn't getting passed during my runs). I finally had a lightbulb moment, but wanted to mention it here in case anyone else runs into the same issue with existing RC1 projects.

Great posts, keep them coming.

Stokes

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Thursday, December 16, 2010 7:11 PM by Michael James

Hi Scott,

I also had problems installing, I dug into the issue and found that the KB patch installer was the issue. By manually installing all the other installers everything seemed to work OK. The KB installer log had the following error: Returning IDOK. INSTALLMESSAGE_ERROR [The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2902. ]

Patch (d:\4111090763ee8b173d0e\VS10-KB2465236.msp) Install failed on product (Microsoft Visual Studio 2010 Express for Windows Phone - ENU). Msi Log:

MSI returned 0x643

Entering Function: MspInstallerT >::Rollback

Initially I thought this was a problem with the Windows Phone tools, but after removing them and retrying I got the same error but this time for the main VS2010 product.

If you need any further details let me know.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Friday, December 17, 2010 3:27 AM by FS

Here's another vote for changing the name of ViewBag to something else. ViewBag just seems wrong. ViewData would ideal but since that's too much work, how about ViewContent, ViewSpace, ViewObject, etc. In my opinion, those would be much better names than ViewBag... :)

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Friday, December 17, 2010 4:58 AM by Ant

Is there something build-in that can assist in placing 'css' and 'script' tags inside a partial control?

The problem is that they need to be placed inside the 'head' tag but there is no way to do that from a partial control.

For example, how do you reuse the same form control for 'create' and 'edit' if there are jquery initialization code?

good effort with the update!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Friday, December 17, 2010 3:25 PM by Jani

You post the most well structured and easy to read content on the web dude, thanks

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Friday, December 17, 2010 8:47 PM by Jay

I tried to install RC2 on top of RC1 using Web PI 3 - after 60 minutes I canceled the installation and had to wait another hour for the rollback.

setup.exe is constantly writing ~200KB/s to HDD but does not finish its operation.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Friday, December 17, 2010 9:51 PM by Jay

After some further investigation I can say, that installation/rollback of vs10-kb2465236-x86.exe doesn't work properly and therefore the whole setup is broken.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 18, 2010 2:30 PM by NNS76

Hi Scott,

Love to read your blogs. Great work.

Is there a chance that you could comment on all the late bound code (Code that is resolved at runtime) that this MVC framework introduces?

What is the reason for this approach? Is this really what people wants?

I have just created a new website using the MVC3 template and its great all the out of the box stuff that this creates but I dont at all fancy the late bound code this template uses. Its hard to debug and maintain.

Examples on late bound code:

1. ViewBag.Title (Set in Views and used in _layout)

2. @Html.Partial("_LogOnPartial") used in _layout

3. @Html.ActionLink("Register", "Register") (I know this is not likely to change name but what if it does and you forget to change it just one place?)

All these issues results in runtime errors but could in the "good" old days have been caught by the compiler by doing following..

1. Using Page.Title or a extension method on Page

2. Using @Register and <object:login...> tag

3. This is pretty much the same but would not resolve in a runtime error but a "not found" page. I dont know which one is better

Am I the only one with this concern?

I understand that you think it is overkill to create an object to pass only a couple of properties but I think that the compiler help helps overcomming this issue. (You could also just create a set of extension methods wich I think is by fare the best extension to C# ever. So effective and powerful)

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, December 18, 2010 4:12 PM by Mark

Awesome Scott but still no declarative helpers? - I asked the same question on the RC1 release in your november post but got no answer. Is this still a feature we can expect in the final release next month?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Sunday, December 19, 2010 7:41 AM by Dmitry

How could I change default message for validation attribute? E.g. when I try to do it following way:

public class MyRequiredAttribute : RequiredAttribute

   {

       public MyRequiredAttribute()

       {

           ErrorMessageResourceName = "Message_Required";

           ErrorMessageResourceType = typeof(Validation);

       }

   }

client-side validation doen't working for this attribute.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 20, 2010 2:57 AM by ryanmch

I let the installer run for over 3 hours and finally decided to cancel. Rollback has now been runnning over an hour. There is something wrong with this installer. It doesn't take VS2010 this long to install. Can someone on the ASP.Net MVC team please look into this?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 20, 2010 12:49 PM by Martin

Has anyone been able to get a view where the model is a string to work?

Try the default template, change the About action to return View("About", "some string"). Then change the view to use @model string.

I get weird errors that no view can be found...

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 20, 2010 3:25 PM by MadMax

Well, tried RemoteAttribute and was very disappointed.

It sends request to server after each character entered into validated field. So when I set remote validation attribute on user name field and enter user name consisting of 10 charcters, jquery sends 10 requests to server (or a bit less - it somehow swallows some keystrokes sometime). More proper will be to send request after some idle timeout (e.g. 1 second) and when user moves focus from input field.

Going to look into jquery.validate plugin, for possible workarounds...

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 21, 2010 7:48 AM by Johann

Has anyone else had SQL intellisense in SSMS stop working after installing MVC3 RC2? It may be a coincidence, but I can't figure out what happened to SSMS.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Thursday, December 23, 2010 2:21 PM by Rupesh Tiwari

As far as I learned MVC strongly supports the separation of concern principle.

But, I found that in UI, we are putting log of logic may be presentation logic. Lot of If, else cases and View (pages) are very much tightly coupled with Models.

So, is the UI independent in MVC and only its concern is to display data? I don’t think.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, December 27, 2010 6:13 PM by Ham

After upgrading and changing all of my "View" and "ViewModel" references, I got the following error on one of my Ajax calls:

The parameters dictionary contains an invalid entry for parameter 'page' for method 'System.Web.Mvc.ActionResult [MethodName](System.Nullable`1[System.Int32], System.Nullable`1[System.Int32], Sakinah.Log.Model.LocationSearchParams)' in 'Sakinah.Website.Controllers.LogController'. The dictionary contains a value of type 'System.Double', but the parameter requires a value of type 'System.Nullable`1[System.Int32]'.

Parameter name: parameters

The page parameter is set in javascript code and is defaulted to zero.

It worked fine prior to the upgrade.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, December 28, 2010 3:09 PM by Unanue

There is no release date mvc3 final version, to be able to plan for products to be manufactured.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 29, 2010 3:37 AM by Three

How can I reset the value of ClientDataTypeModelValidatorProvider_FieldMustBeNumeric in the MvcResources.resx?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, December 29, 2010 4:31 AM by wuwen218

I am using jquery for client side validation together with data annotations. Everything is working fine but I would like to localize a message when a non numeric value is entered in numeric textbox. But for client side validation asp.net mvc is using it's own resource file with key 'ClientDataTypeModelValidatorProvider_FieldMustBeNumeric'.

How can I do?

Thanks.

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Thursday, December 30, 2010 9:40 PM by LWNorthcutt

After I installed the MVC3 download and then open vs2010 on my XP sp3 machine, i got the following error messages (too many to count and then i just killed the process):

"The 'VSTS for Database Professionals Sql Server Data-tier Application' package did not load correctly."

I never had this issue before the install.  What's going on ?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Thursday, December 30, 2010 9:55 PM by LWNorthcutt

UPDATE -

I just UN-Installed MVC3, re-opened VS2010 and now I have no issue.  So my guess is there is something still amiss with mvc3.

re:

After I installed the MVC3 download and then open vs2010 on my XP sp3 machine, i got the following error messages (too many to count and then i just killed the process):

"The 'VSTS for Database Professionals Sql Server Data-tier Application' package did not load correctly."

I never had this issue before the install.  What's going on ?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, January 1, 2011 12:19 AM by sadegh-shad

Where is located Html.Raw()? I haven't access to this!

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, January 4, 2011 10:57 PM by Franck

Hi Scott,

Let's say I got an application that uses ASP.NET MVC but I want to utilize the jquery template and data-linking plugins so to move the purely UI stuff on the client side. I imagine that any view engine whether they are razor or the default one, they " parse " the view code and spit out HTML at the end. But is there a way to " disable " this parsing step so that I can have a product view that is purely HTML with Javascript (let's say Product.htm) and within my controller code I can do something like ' return View("Product") '.

The question is, can I entirely skip the parsing step if I know my view contains only HTML and Javascript ?

Thx for all the interesting blog articles !

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, January 5, 2011 1:21 AM by ScottGu

@Franck,

>>>>>>> Let's say I got an application that uses ASP.NET MVC but I want to utilize the jquery template and data-linking plugins so to move the purely UI stuff on the client side. I imagine that any view engine whether they are razor or the default one, they " parse " the view code and spit out HTML at the end. But is there a way to " disable " this parsing step so that I can have a product view that is purely HTML with Javascript (let's say Product.htm) and within my controller code I can do something like ' return View("Product") '.  The question is, can I entirely skip the parsing step if I know my view contains only HTML and Javascript ?

The good news is that our parser is pretty smart, and we cache the results of any parsing we do (even across application restarts).  This means that you don't need to worry about this performance overhead.

Hope this helps!

Scott

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Wednesday, January 5, 2011 11:36 AM by Brent

In the unobtrusive validation link you mention it shows a couple settings, ClientValidationEnabled and UnobtrusiveJavaScriptEnabled, that are implemented as basic "appSettings" elements in web.config.  Is there a reason these don't live somewhere under the "strongly typed" system.web configuration element?  Having gotten rid of all appSettings in my own projects years ago in favor of custom configuration sections, it makes me sad to think I'm going to be required to have appSettings back in my web.config again.  Any chance they might move in the RTM?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Saturday, January 8, 2011 4:47 PM by DotNetWise

I would love to see in the RTM the ability to have this overloaded RenderSection version:

<meta name="keywords" content="@this.RenderSection("meta.keywords", @<text>Sensient</text>)" />

For now defined as an extended method:

public static class SectionExtensions

{

private static readonly object _o = new object();

public static HelperResult RenderSection(this WebPageBase page,

string sectionName,

Func<object, HelperResult> defaultContent)

{

if (page.IsSectionDefined(sectionName))

{

return page.RenderSection(sectionName);

}

else

{

return defaultContent(_o);

}

}

}

#1 get rid of this, thus include the extended methods by default

#2 the ability to use @: instead of @<text>aaaa</text>, athough is hard to tell when the text ends

#3 due to a bug in Razor (I think) the whitespace after the comma and before @ (e.g. ...RenderSection("meta.keywords", @<text...) is rendered as well (which should not be the case as VS2010 automatically includes it when you do format the document

What do you think Scott?

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Monday, January 10, 2011 7:30 AM by Andrew Tierney

Do you have a ASP.NET MVC 3.0 RTM date ? Previously you mentioned Mid Jan 2011.

I would like to hold off on RC2 and jump straight to RTM for my new project.

Thanks

Andrew Tierney

CastleSoft

# re: Announcing ASP.NET MVC 3 (Release Candidate 2)

Tuesday, January 11, 2011 7:39 AM by Andrew Tierney

Any word on MVC 3.0 RTM ?