ASP.NET MVC 2 (Release Candidate 2) Now Available

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

Earlier this evening the ASP.NET team shipped ASP.NET MVC (Release Candidate 2) for VS 2008/.NET 3.5.  You can download it here.

The RC2 release of ASP.NET MVC 2 is a follow-up to the first ASP.NET MVC 2 RC build that we shipped in December.  It includes a bunch of bug fixes, performance work, and some final API and behavior additions/changes.  Below are a few of the changes between the RC1 and RC2 release (read the release notes for even more details):

  • The new ASP.NET MVC 2 validation feature now performs model-validation instead of input-validation (this means that when you use model binding all model properties are validated instead of just validations on changed values of a model).  This behavior change was based on extensive feedback from the community.
  • The new strongly-typed HTML input helpers now support lambda expressions which reference array or collection indexes.  This means you can now write code like Html.EditorFor(m=>m.Orders[i]) and have it correctly output an HTML <input> element whose “name” attribute contains the index (e.g. Orders[0] for the first element), and whose “value” contains the appropriate value.
  • The new templated Html.EditorFor() and Html.DisplayFor() helper methods now auto-scaffold simple properties (and do not render complex sub-properties by default).  This makes it easier to generate automatic scaffolded forms.  I’ll be covering this support in a future blog post.
  • The “id” attribute of client-script validation message elements is now cleaner.  With RC1 they had a form0_ prefix.  Now the id value is simply the input form element name postfixed with a validationMessage string (e.g. unitPrice_validationMessage).
  • The Html.ValidationSummary() helper method now takes an optional boolean parameter which enables you to control whether only model-level validation messages are rendered by it, or whether property level validation messages are rendered as well.  This provides you with more UI customization options for how validation messages are displayed within your UI.
  • The AccountController class created with the default ASP.NET MVC Web Application project template is cleaner.
  • Visual Studio now includes scaffolding support for Delete action methods within Controllers, as well as Delete views (I always found it odd that the default T4 templates didn’t support this before).
  • jQuery 1.4.1 is now included by default with new ASP.NET MVC 2 projects, along with a –vsdoc file that provides Visual Studio documentation intellisense for it.
  • The RC2 release has some significant performance tuning improvements (for example: the lambda based strongly-typed HTML helpers are now much faster).

Today’s RC2 release only work with VS 2008 and .NET 3.5.  We’ll shortly be releasing the VS 2010 RC (which will be available for everyone to download). It will include ASP. NET MVC 2 support built-in (no separate download required).

Hope this helps,

Scott

P.S. The source code for the ASP.NET MVC RC2 release (along with a MVC futures library that goes with it) can be downloaded here. You can learn even more about ASP.NET MVC 2 by reading the ASP.NET MVC 2 blog series I’m working on.

53 Comments

  • Any news on the fix to the TryUpdateModel problem, Scott? http://stackoverflow.com/questions/1936970/asp-net-mvc-2-problem-with-updatemodel

  • Hi Scott,
    I have a question regarding this statement:

    "the lambda based strongly-typed HTML helpers are now much faster"

    Is there any place we can read more about this improvement - how it was achieved? (besides the source code itself of course:) ).

  • I wonder how shortly are you releasing the VS 2010 RC? Is it a matter of hours, days or weeks? :-)

    In other words; should I cancel my plans for the weekend?

  • Thanks for all your hard work!

  • @horacebury - Since the code is open source - you can check out the source code and see if it's been fixed. You'll notice that it has been changed (the FormCollection GetValue problem) to fix this bug.

    Cheers,

    ChrisNTR

  • Hi Scott,

    Any chance of getting model based scaffolded controllers (like we can have views)? This way we could make our own templates and very quickly generate CRUD's?

    Also, any chance of multi templates? So that you could select from a list of template folders (that way we could create several templates for example for controllers...one for CRUD, one for normal controllers and such...), and then just use it as appropriate (something similar like you can select view content...list template, detail, etc...)


    Thanks,
    Vladan

  • Hi,

    RE: Html.ValidationSummary() I thought latest thinking was that "magic" boolean parameters were a bad thing & better practice was to actually supply a more descriptive Enum?

    Thanks,

    Howard

  • @horacebury
    From the release notes:
    "The GetValue method of the FormCollection class now allows empty string values."
    -raj

  • Very good !
    Thank you for "model-validation instead of input-validation"!

  • great!

    I'll do some tests ^^

  • One problem I encountered in MVC2 is with subfolders (containing css, images or js) in Areas. For example: mysite.com/admin/css/adminstyles.css. I tried creating a folder in projectroot/Areas/Admin/css/ and projectroot/Admin/css/ but neither worked when I tested my site.
    Is there some solution for this?

  • Great news!
    Cheers

  • Hi Scott,

    Yes I'm impatient .. grin. Any idea when VS 2010 RC will be released. The reason I ask is that I am currently making the move to MVC (for some non critical projects) and am currently working with VS2010 Beta 2 which I undrerstand is a little behind in the MVC area. Just wondered if I should abort VS 2010 Beta 2 for the moment and install MVC RC2 for VS 2008. But if the VS2010 RC is close I'll hold off.

    Thanks.

  • What about migration from MVC1 to MVC2 RC2? So far i've seen only migration tool to beta, is it safe to use it to migrate to rc2?

  • Thanks for the great work. We've really like MVC, and I think it's one of the best things MS had delivered!

    Patrick

  • Html.EditorFor(m=>m.Orders[i])

    Finally!

  • Fantastic news! Thanks.

  • Hello, can I host MVC2 RC2 in ISS 7? I try this with MVC2 RC1, but it don't work. Thank you for answer.

  • Thanks for early release.

  • @horacebury

    >>>>>>>> Any news on the fix to the TryUpdateModel problem, Scott? stackoverflow.com/.../asp-net-mvc-2-problem-with-updatemodel

    Yes - I believe that is now fixed. Let me know if you still run into issues with it.

    Thanks,

    Scott

  • thanks for jQuery 1.4.1.

  • Great work guys - really excited for the Model Validation change.

    As for this: Html.EditorFor(m=>m.Orders[i])

    How about Html.EditorFor(m => m.Orders[i].Name) ? will I end up with Orders[n].Name in the id/name tag (where [n] is the index number)?

  • Anybody else not getting Intellisense for jQuery 1.4.1 in Visual Studio 2008 SP1 with the JS Intellisense patch installed? I copied the old jQuery libraries from the previous MVC RC1 and Intellisense works. But doesn't seem to work for version 1.4.1. Is there something I'm missing?

  • Ahhh can't wait for the new VS 2010 RC!!!

  • Is there an upgrade path for asp.net mvc 1.0 in this ?

    Also, I'm running 2010, can I roll back my project to 2008 then install this?

  • How long is "shortly" in reference to VS 2010 RC, or can you not give us an exact date/estimate? Will it support ASP.NET MVC 2 RC 2 or just RC 1?

  • Congratulation! I'll update MvcPager to use asp.net mvc RC2.

  • Creating silverlight on asp.net mvc are now easy. Thanks for the tutorials I like how you have presented the information in full detail. Keep up the great work

  • Hi Scott,
    How to make Html.EditorFor() render complex sub-properties?
    [ScaffoldColumn(true)] isn't enough.

  • Yap. Intellisense dosnt work with jquery 1.4.1.

  • The bullet point #3 is not what I expected and I think it will make the ModelMetadata very limited. As you have mention and also in the read me says it should work for complex object if any template file is used. But unfortunately it does not work even if you set a template file. For example if I have class with the follwing:

    public class Product{
    public int Id { get; set;}
    public string Name { get; set;}
    public decimal Price { get; set;}
    [UIHint("myCustomTemplate")]
    public Category Category { get; set;}
    }

    And in my view (which uses the Product as Model ViewPage) if I use:


    If will not show the category only the Id, Name, Price will be shown.

    I think this is somehow a show stopper for those who are thinking to create scaffolding framework to auto generate the UI.

  • @Maciej,

    >>>>>>>>> Is there any place we can read more about this improvement - how it was achieved? (besides the source code itself of course:) ).

    The source might be the best option (it is available for download too as a separate project). I believe we added a bunch of caching logic to speed this up.

    Hope this helps,

    Scott

  • @Klaus,

    >>>>>>>>> I wonder how shortly are you releasing the VS 2010 RC? Is it a matter of hours, days or weeks? :-)

    It won't be released this weekend. But it will be soon... ;-)

    Hope this helps,

    Scott

  • @Vladan,

    >>>>>>> Any chance of getting model based scaffolded controllers (like we can have views)? This way we could make our own templates and very quickly generate CRUD's? Also, any chance of multi templates? So that you could select from a list of template folders (that way we could create several templates for example for controllers...one for CRUD, one for normal controllers and such...), and then just use it as appropriate (something similar like you can select view content...list template, detail, etc...)

    Those are definitely good suggestions and ones I think you'll see show up in the future. For ASP.NET MVC 2 we unfortunately won't have this in the built-in controller dialog - but I expect others to probably create extensions that support this.

    Hope this helps,

    Scott

  • @Howard,

    >>>>>>>>> RE: Html.ValidationSummary() I thought latest thinking was that "magic" boolean parameters were a bad thing & better practice was to actually supply a more descriptive Enum?

    Good comment. I'll forward it along to the team to see what they say.

    Thanks,

    Scott

  • @ZippyV,

    >>>>>>>> One problem I encountered in MVC2 is with subfolders (containing css, images or js) in Areas. For example: mysite.com/admin/css/adminstyles.css. I tried creating a folder in projectroot/Areas/Admin/css/ and projectroot/Admin/css/ but neither worked when I tested my site.

    You should be able to do this. How are you referencing the files? Are you prefixing the css URL with a /Area/Admin/css prefix?

    Thanks,

    Scott

  • @Simon,

    >>>>>>>>> Yes I'm impatient .. grin. Any idea when VS 2010 RC will be released. The reason I ask is that I am currently making the move to MVC (for some non critical projects) and am currently working with VS2010 Beta 2 which I undrerstand is a little behind in the MVC area. Just wondered if I should abort VS 2010 Beta 2 for the moment and install MVC RC2 for VS 2008. But if the VS2010 RC is close I'll hold off.

    It will be out pretty shortly. Stay tuned to my blog for details.

    Hope this helps,

    Scott

  • @Gierdrius,

    >>>>>>>>> What about migration from MVC1 to MVC2 RC2? So far i've seen only migration tool to beta, is it safe to use it to migrate to rc2?

    There are migration notes in the release notes. You can do it either manually (updating the project+references - should only take a few minutes). VS 2010 will also include an automatic upgrade wizard that will help automate it.

    Hope this helps,

    Scott

  • @Deny,

    >>>>>>>> Hello, can I host MVC2 RC2 in ISS 7? I try this with MVC2 RC1, but it don't work. Thank you for answer.

    This should just work. What problem did you run into?

    Thanks,

    Scott

  • @Steve,

    >>>>>>>>> How about Html.EditorFor(m => m.Orders[i].Name) ? will I end up with Orders[n].Name in the id/name tag (where [n] is the index number)?

    The good news is that this works as well.

    Hope this helps,

    Scott

  • @Steve,

    >>>>>>>> Also, I'm running 2010, can I roll back my project to 2008 then install this?

    Yes - you could do that. What you'd want to-do is to go to add/remove programs and uninstall the ASP.NET MVC 2 bits (the runtime + VS tools support for ASP.NET MVC items). Then you can download and install the ASP.NET MVC 2 RC2 above and use it with VS 2008.

    Hope this helps,

    Scott

  • @Michel,

    >>>>>> How to make Html.EditorFor() render complex sub-properties?

    I think you need to create a template for the object in order to render sub-properties. I will ping the dev team to see if they've thought of adding a flag to EditorFor() that enables this too.

    Hope this helps,

    Scott

  • @kazimanzurrashid,

    >>>>>>>>>> The bullet point #3 is not what I expected and I think it will make the ModelMetadata very limited. As you have mention and also in the read me says it should work for complex object if any template file is used. But unfortunately it does not work even if you set a template file.

    I think to render complex sub-properties you need to override the template for the object itself. I'll ping the dev team, though, to see if there is a way with the RTM build to enable a flag for this too.

    Hope this helps,

    Scott

  • Ignore what I just said. I got vsdoc for jquery 1.4.1 from VS2008. But like some comments said. I cannot get intellisense as well. when typing js code in vs2010. Intellisense only shows function parameter without any comment.

  • False alarm - I see the problem now. You have to include /Areas/ in the URL... which makes perfect sense. My bad.

  • I just swapped out RC1 for RC2 in my application and model binding to a list appears broken. At least when you specify the index. Anyone else see this?

  • >>>>>>>>>>>>>>>> The new strongly-typed HTML input helpers now support lambda expressions which reference array or collection indexes. This means you can now write code like Html.EditorFor(m=>m.Orders[i]) and have it correctly output an HTML element whose “name” attribute contains the index (e.g. Orders[0] for the first element), and whose “value” contains the appropriate value.

    This function does not work actually with the MVC version "shipped" in VS 2010 RC... Name output is "Orders"...

  • @Dan A

    Was looking for binding a list... Had used a logic approach for naming fields :

    Item[0].Property0
    Item[0].Property1
    Item[1].Property0
    Item[1].Property1

    And it works fine, without Index

  • Hi, Thanks for latest release and Model level Validation. I have facing the following problem after the update.

    I have a Model with Class level Validation plus property level validation in it. After updating to MVC 2 RC 2. The model validation fails on Model binding. What i actually understand that new mechanism trying to validate the model when you first request it or say on GET and it get null object exception during tryvalidatemodel Model binding call.

    My Model is like this below

    [Serializable]
    [MetadataType(typeof(InterestClaimMetaData))] //metadata with all properties level validation

    //these validations fails when you request a page.
    [DateComparison("DateA", "DateB", eDateComparitor.GreaterThan, ErrorMessage = "Date A must be greater than B Date")][MutuallyExclusive("A", "B", ErrorMessage = "Please select either A or B field")]

    public class IE
    {
    public int ID { get; set; }
    public byte[] Updated { get; set; }
    }


    DataComparison and MutuallyExclusive overrides the validate function isvalid and check the validation but it fails trying to validate as first requested.
    dont know how to stop this happening as it should not validate model on get request; just attach the properties.

    Only models without these class level validation works.

    Please advise.
    Thanks

  • What would be the problem that using Jason data and jQuery with MVC 1 works o.k. and the same functions using MVC 2 CR2 don't work ??
    Example the using the jqGrid to show data in a grid running in MVC 1 works o.k. in the page you see the grid with the data passed by Jason from a action in controler. The same code with MVC 2 you see the grid in the page but empty. It's like it has a problem receiving the Jason data.

  • asp.net mvc 2 Not perfect,in Areas Should Achieve 2 domain Route.Official Version To consider.

    public class HomeAreaRegistration : AreaRegistration

    {

    public override string AreaName

    {

    get

    {

    return "Home";

    }

    }

    public override void RegisterArea(AreaRegistrationContext context)

    {

    context.MapRoute(

    "Home_default",

    "Home/{controller}/{action}/{id}",

    new { controller = "Home", action = "Index", id = "" },

    new string[] { "Ghaozi.HomeAreas.Controllers" }

    );

    // context.MapDomainRoute(

    // "Home_default",

    // "{controller}.asp.net/{action}/{id}", // URL with parameters

    // new { controller = "Home", action = "Index", id = "" } // Parameter defaults

    // );

    }

    }

  • asp.net mvc 2 Not perfect,in Areas Should Achieve 2 domain Route.Official Version To consider.

    public class HomeAreaRegistration : AreaRegistration

    {

    public override string AreaName

    {

    get

    {

    return "Home";

    }

    }

    public override void RegisterArea(AreaRegistrationContext context)

    {

    context.MapRoute(

    "Home_default",

    "Home/{controller}/{action}/{id}",

    new { controller = "Home", action = "Index", id = "" },

    new string[] { "Ghaozi.HomeAreas.Controllers" }

    );

    // context.MapDomainRoute(

    // "Home_default",

    // "{controller}.asp.net/{action}/{id}", // URL with parameters

    // new { controller = "Home", action = "Index", id = "" } // Parameter defaults

    // );

    }

    }

  • So that you could select from a list of template folders that way we could create several templates for example for controllers one for CRUD, one for normal controllers and such.

Comments have been disabled for this content.