ASP.NET MVC Preview 3 Release

This morning we released the Preview 3 build of the ASP.NET MVC framework.  I blogged details last month about an interim source release we did that included many of the changes with this Preview 3 release.  Today's build includes some additional features not in last month's drop, some nice enhancements/refinements, as well as Visual Studio tool integration and documentation.

You can download an integrated ASP.NET MVC Preview 3 setup package here.  You can also optionally download the ASP.NET MVC Preview 3 framework source code and framework unit tests here.

Controller Action Method Changes

ASP.NET MVC Preview 3 includes the MVC Controller changes we first discussed and previewed with the April MVC source release, along with some additional tweaks and adjustments. 

You can continue to write controller action methods that return void and encapsulate all of their logic within the action method.  For example:

which would render the below HTML when run:

Preview 3 also now supports using an approach where you return an "ActionResult" object that indicates the result of the action method, and enables deferred execution of it.  This allows much easier unit testing of actions (without requiring the need to mock anything).  It also enables much cleaner composition and overall execution control flow.

For example, we could use LINQ to SQL within our Browse action method to retrieve a sequence of Product objects from our database and indicate that we want to render a View of them.  The code below will cause three pieces of "ViewData" to be passed to the view - "Title" and "CategoryName" string values, and a strongly typed sequence of products (passed as the ViewData.Model object):

One advantage of using the above ActionResult approach is that it makes unit testing Controller actions really easy (no mocking required).  Below is a unit test that verifies the behavior of our Browse action method above:

 

We can then author a "Browse" ViewPage within the \Views\Products sub-directory to render a response using the ViewData populated by our Browse action:

When we hit the /Products/Browse/Beverages URL we'll then get an HTML response like below (with the three usages of ViewData circled in red):

Note that in addition to support a "ViewResult" response (for indicating that a View should be rendered), ASP.NET MVC Preview 3 also adds support for returning "JsonResult" (for AJAX JSON serialization scenarios), "ContentResult" (for streaming content without a View), as well as HttpRedirect and RedirectToAction/Route results.  

The overall ActionResult approach is extensible (allowing you to create your own result types), and overtime you'll see us add several more built-in result types.

Improved HTML Helper Methods

The HTML helper methods have been updated with ASP.NET MVC Preview 3.  In addition to a bunch of bug fixes, they also include a number of nice usability improvements.

Automatic Value Lookup

With previous preview releases you needed to always explicitly pass in the value to render when calling the Html helpers.  For example: to include a value within a <input type="text" value="some value"/> element you would write:

The above code continues to work - although now you can also just write:

The HTML helpers will now by default check both the ViewData dictionary and any Model object passed to the view for a ProductName key or property value to use.

SelectList and MultiSelectList ViewModels

New SelectList and MultiSelectList View-Model classes are now included that provide a cleaner way to populate HTML dropdowns and multi-select listboxes (and manage things like current selection, etc).  One approach that can make form scenarios cleaner is to instantiate and setup these View-Model objects in a controller action, and then pass them in the ViewData dictionary to the View to format/render. 

For example, below I'm creating a SelectList view-model class over the set of unique category objects in our database.  I'm indicating that I want to use the "CategoryID" property as the value of each item in the list, and the "CategoryName" as the display text.  I'm also setting the list selection to the current CategoryId of the Product we are editing:

Within our view we then just have to write the below code to indicate that we want to create a drop-downlist against the SelectList we put into ViewData:

This will then render the appropriate drop down with items and selection for us at runtime:

 

Built-in error validation support isn't included with our HTML helpers yet (you currently need to write code for this) - but will show up in the future, which will make form editing scenarios even easier.

You'll also start to see ASP.NET AJAX helper methods show up in future preview releases as well, which will make it easier to integrate AJAX into MVC applications with a minimum of code.

URL Routing Improvements

ASP.NET MVC Preview 3 includes a number of improvements to the URL routing system.  URL routing is one of the most "fundamental" components of a web MVC framework to get right, hence the reason we've spent a lot of focus the first few previews getting this area nailed.  Our new URL routing engine will ship in .NET 3.5 SP1 this summer, and will support both Web Forms and MVC requests.  ASP.NET MVC will be able to use the built-in .NET 3.5 SP1 routing engine when running on .NET 3.5 SP1. ASP.NET MVC will also include its own copy of the assembly so that it can also work on non-SP1 systems.

Some of the URL Routing Improvements in the Preview 3 release include:

MapRoute() and IgnoreRoute() helper methods

ASP.NET MVC Preview 3 includes new "MapRoute" and "IgnoreRoute" helper methods that you can use to more easily register routing rules.  MapRoute() provides an easy way to add a new MVC Route rule to the Routes collection.  IgnoreRoute() provides an easy way to tell the URL routing system to stop processing certain URL patterns (for example: handler .axd resources in ASP.NET that are used to serve up JavaScript, images, etc). 

Below is an example of the default RegisterRoutes() method within Global.asax when you create a new ASP.NET MVC project where you can see both of these new helper methods in action. 

The MapRoute() helper method is overloaded and takes two, three or four parameters (route name, URL syntax, URL parameter default, and optional URL parameter regular expression constraints). 

You can call MapRoute() as many times as you want to register multiple named routes in the system.  For example, in addition to the default convention rule, we could add a "Products-Browse" named routing rule like below:

We can then refer to this "Products-Browse" rule explicitly within our Controllers and Views when we want to generate a URL to it.  For example, we could use the Html.RouteLink view helper to indicate that we want to link to our "Products-Browse" route and pass it a "Food" category parameter using code in our view template like below:

This view helper would then access the routing system and output an appropriate HTML hyperlink URL like below (note: how it did automatic parameter substitution of the category parameter into the URL using the route rule):

We could alternatively use the new Url.RouteUrl(routeName, values) within views if we wanted to just retrieve the URL for a named route (and not output the <a> html element). 

We could also use the new RedirectToRoute(routeName, values) helper method on the Controller base class to issues browser redirects based on named routing rules. 

Richer URL Route Mapping Features

ASP.NET MVC Preview 3 also supports a bunch of new URL route mapping features.  You can now include "-", ".", ";" or any other characters you want as part of your route rules.

For example, using a "-" separator you can now parse the language and locale values from your URLs separately using a rule like below:

This would pass appropriate "language", "locale", and "category" parameters to a ProductsController.Browse action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
{language}-{locale}/products/browse/{category} /en-us/products/browse/food language=en, locale=us, category=food
  /en-uk/products/browse/food language=en, locale=uk, category=food

Or you can use the "." file extension type at the end of a URL to determine whether to render back the result in either a XML or HTML format:

This would pass both "category" and a "format" parameters to the ProductsController.Browse action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
products/browse/{category}.{format} /products/browse/food.xml category=food, format=xml
  /products/browse/food.html category=food, format=html

ASP.NET MVC Preview 3 also supports wildcard route rules (these were also in Preview 2).  For example, you can indicate in a rule to pass all remaining URI content on as a named parameter to an action method:

This would pass a "contentUrl" parameter to the WikiController.DisplayPage action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
Wiki/Pages/{*contentUrl} /Wiki/Pages/People/Scott contentUrl="People/Scott"
  /Wiki/Pages/Countries/UK contentUrl="Countries/UK"

These wildcard routes are very useful to look at if you are building a blogging, wiki, cms or other content based system.

Summary

Today's Preview 3 release of ASP.NET MVC includes a bunch of improvements and refinements.  We are starting to feel good about the URL routing and Controller/Action programming model of MVC, and feel that those areas are starting to bake really well.  In future preview releases you'll start to see more improvements higher-up the programming model stack in areas like Views (html helpers, validation helpers, etc), AJAX, sub-controllers and site composition, deeper Login, Authentication, Authorization and Caching integration, as well as data scaffolding support. 

I also have a (very) long tutorial post that I started putting together this past weekend that walks-through building an application using ASP.NET MVC Preview 3 that I'm hoping to wrap up and post in the next few days.  This should provide both a good intro to ASP.NET MVC, as well as help provide some context on how all the pieces fit together if you are interested in using the ASP.NET MVC option.

Hope this helps,

Scott

Published Tuesday, May 27, 2008 1:26 PM by ScottGu
Filed under: , , ,

Comments

# ASP.NET MVC Preview 3 available | DavideZordan.net

Tuesday, May 27, 2008 4:43 PM by ASP.NET MVC Preview 3 available | DavideZordan.net

Pingback from  ASP.NET MVC Preview 3 available | DavideZordan.net

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 4:47 PM by Steven

Slightly off topic question, but what color scheme are you using in VS? Can you provide a download link for it?

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 4:56 PM by Andrew Davey

Instead of a single ActionResult why not have a "List<ControllerAction>" property on Controller. This allows multiple actions to be queued easily. For example: SetStatusCode, WriteCookie, RenderPage

The action methods can return void once more. You can provide methods in Controller that add actions to the list e.g. RenderView(data). There could also be a general "DoAction" method.

Testing is still easy since a test can inspect the contents of the action list.

In addition, you can have (via extension methods) tests like:

Assert.That(homeController.DidRenderView("homepage"));

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 4:57 PM by Elijah Manor

That is great! I look forward to using the new Preview. Do you know when Scott Hanselman's updated screen casts for Preview 3 will be on the ASP.NET MVC website?

# ASP.NET MVC Preview 3 Released

Tuesday, May 27, 2008 4:59 PM by Chris Bowen's Blog

Great news from the team that's working on bringing Model View Controller to ASP.NET - the Preview 3

# ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:10 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:11 PM by Vasilio Ruzanni

Delllliiicious!!! Can't wait the ASP.NET MVC to be released. I invest a lot to my team developing using all the Preview releases of MVC Framework but I'd be in total happiness to invest even more when all risks of breaking changes are gone.

Thanks for your work!

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:14 PM by threak

Nice, JSON support is really kicking ass.

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:14 PM by Chris Sutton

This is looking really good. I like what has been happening with routing.

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:15 PM by Jim

Hey Scott,

Quick question of unit testing controller actions without mocking.  Can you describe how you would test actions that except POST data?  For example, an Authenticate action that accepts a username and password.

Congrats on the release!

Jim

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:16 PM by Elliot Gage

Yes! None to soon. I have a couple of projects I have been holding off on starting; have been waiting for this release.

Thanks again!

# ASP.NET MVC Preview 3 is out

Tuesday, May 27, 2008 5:27 PM by LA.NET [EN]

As always, Scott Guthrie has announced it on his blog (let&#39;s see if I can keep up with all the work

# ASP.NET MVC Preview 3 Announced

Tuesday, May 27, 2008 5:31 PM by ASPInsiders

Scott Guthrie just posted about the 3rd preview of the ASP.NET MVC over on his blog. You can catch the

# ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:36 PM by codebeater

ASP.NET MVC Preview 3 Release

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:41 PM by Joseph Ferner

Why are the form controls not strongly typed?  I feel like something like Html.TextBox(model=>model.FieldName); should be possible. Or maybe something with the form...

<% using(MvcForm form=Html.Form<MyModelObject>(ViewData.MyData)) { %>

 <%= form.TextBox(m=>m.FieldName) %>

<% } %>

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:45 PM by Anthony Synjsi

Hello,

Url Routing replace Url Rewritter?

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 5:49 PM by Ranjit Nene

Great Post!! How do you manage to write so well.

I really appreciate your work.

Thanks,

RN

# ASP.NET MVC Preview 3 released | Code-Inside Blog

Tuesday, May 27, 2008 6:02 PM by ASP.NET MVC Preview 3 released | Code-Inside Blog

Pingback from  ASP.NET MVC Preview 3 released | Code-Inside Blog

# ASP.NET MVC Preview 3 released | Code-Inside Blog International

Pingback from  ASP.NET MVC Preview 3 released | Code-Inside Blog International

# ASP.NET MVC Preview 3 Released - Nick Berardi&#8217;s Coder Journal

Pingback from  ASP.NET MVC Preview 3 Released - Nick Berardi&#8217;s Coder Journal

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 6:37 PM by EricTN

Hi Scott!  Going forward, would ASP.NET MVC also support the ability to use an RIA front-end like Silverlight with MVC?  If an RIA front-end was used as the View, how could we pass ViewData from the Controller to it?

# { null != Steve } &raquo; ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 6:39 PM by { null != Steve } » ASP.NET MVC Preview 3 Release

Pingback from  { null != Steve } &raquo; ASP.NET MVC Preview 3 Release

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 6:45 PM by Dominic Pettifer

I'm looking forward to how you end up implementing the Html Form Validation Helpers, as this is an area I am still unsure on how to implement properly without the ASP.NET Form PostBack/ViewState safety net. But that won't be for another release, do you have a timeframe for release 4, and will the Validation Helpers be part of it?

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 6:51 PM by Clashfan

Just found out about asp.net mvc today. Looks really cool. It seems like it's based alot on Rails, is this true?

# ASP.NET MVC Preview 3

Tuesday, May 27, 2008 7:18 PM by Scott Hanselman's Computer Zen

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 7:20 PM by Erik

So how does this relese play with SP1?

# ASP.NET MVC Preview 3

Tuesday, May 27, 2008 7:39 PM by ASPInsiders

The Gu has announced another regular drop of ASP.NET MVC . This one is Preview 3 and the goodness can

# ASP.NET MVC Preview 3 esta aquí

Tuesday, May 27, 2008 7:41 PM by DotNetMania@GT

El d&#237;a de hoy Scott Gu , ha hecho oficial la liberaci&#243;n del ASP.NET MVC Preview 3 el cual incluye

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 7:42 PM by Padgett

Nice work, gotta say I’m loving this so far.

One question:  In preview 2 you couldn’t overload action methods, will this change?

E.g. You can’t do this:

public ActionResult ShowProducts(int category) {...}

public ActionResult ShowProducts(int category, int subCategory) {...}

public ActionResult ShowProducts(int category, int subcategory, int someOtherFieldToFilterOn) {...}

Should I be using the most expressive method and just making each param nullable?

# ASP.NET MVC Preview 3 esta aqu&#237; &laquo; Blog de Carlos Lone

Pingback from  ASP.NET MVC Preview 3 esta aqu&#237; &laquo; Blog de Carlos Lone

# ASP.NET MVC Preview 3 Release | .Net

Tuesday, May 27, 2008 8:35 PM by ASP.NET MVC Preview 3 Release | .Net

Pingback from  ASP.NET MVC Preview 3 Release  | .Net

# ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 8:53 PM by Shawn Chi

ASP.NET MVC Preview 3 Release

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 9:03 PM by benb

Does it play well with the SP1 Beta?

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 9:35 PM by Tim Dougall

Thanks Scott.

It's really great to see (and use) the MVC framework as it evolves - muchas gracias!

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 9:45 PM by MVC User

Well done! But it seems MVC is still at its babyhood.

Hope funcs of AJAX, sub-controllers and site composition, deeper Login, Authentication, Authorization and Caching integration will be here soon.

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 9:47 PM by shiju

Has this version support VWD express 2008?

# ASP.NET MVC Preview 3 | Developer Home

Tuesday, May 27, 2008 10:00 PM by ASP.NET MVC Preview 3 | Developer Home

Pingback from  ASP.NET MVC Preview 3 | Developer Home

# ASP.Net MVC Preview 3 Released

Tuesday, May 27, 2008 10:11 PM by Shiju Varghese's Blog

ASP.net MVC preview has been released. You can download Preview 3 version from here . Resources of MVC

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 10:30 PM by Paul Kohler

This is looking really good - I like the testable changes to the Action Result.

Question... I may be off track a bit but is there an easy way for me (in a unit test for example) to test the "view output" *given* a set of view data. e.g. I create some known view data such as page title, product list etc and push that into the view render engine giving me a string (what is ultimately sent to the browser). I then want to be able to perform asserts etc on the string to look for certain data (or the absense of it).

Even better, in the designer having the same pricipal for the preview mode saving the whole cycle of building/running the site to check changes to the rendered view.

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 10:32 PM by ScottGu

Hi Andrew,

>>>>>> Instead of a single ActionResult why not have a "List<ControllerAction>" property on Controller. This allows multiple actions to be queued easily. For example: SetStatusCode, WriteCookie, RenderPage  The action methods can return void once more. You can provide methods in Controller that add actions to the list e.g. RenderView(data). There could also be a general "DoAction" method.

It is an interesting idea, and one we looked at a little.  A couple of the nice things about the return approach, though, are that it allows chaining of filters and actions - for example, one filter could intercept the result, change/transform it (or replace it), and then pass it along.  It makes execution control flow a easier to read (since you can return from anywhere).  And in the future it will make async execution (where you yield the worker thread) as well as sub-controllers easier to build.

There are actually a number of popular MVC frameworks out there (including Django and Tapestry) that use this approach - so it is also a pretty proven pattern.

The good news, though, is that the ASP.NET MVC framework is extensible - so if you prefer a void approach using a List to track results you can implement one without too much effort, and re-use everything else in ASP.NET MVC.

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 10:33 PM by ScottGu

Hi Elijah,

>>>>>>> That is great! I look forward to using the new Preview. Do you know when Scott Hanselman's updated screen casts for Preview 3 will be on the ASP.NET MVC website?

I saw that Scott just posted some new videos earlier today: www.hanselman.com/.../ASPNETMVCPreview3.aspx

Enjoy!

Scott

# ASP.NET MVC Preview 3 が日本語版 VS 2008 対応でリリース

Tuesday, May 27, 2008 10:39 PM by ナオキにASP.NET(仮)

ScottGu's Blog 、 Scott Hanselman's ComputerZen.com 、 you've been hacked and you like it からです。 ASP.NET

# ASP.NET MVC Framework Preview 3 Released - ActionResult Object and Deferred Execution - Better Url Routing and Helpers Too

You gotta love the easier testing that the ASP.NET MVC Preview 3 brings to the table. Up until now I still preferred testing Model-View-Presenter.

# Programando em .NET &raquo; ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 10:46 PM by Programando em .NET » ASP.NET MVC Preview 3 Release

Pingback from  Programando em .NET    &raquo; ASP.NET MVC Preview 3 Release

# Lançamento da ASP.NET MVC Preview 3

Tuesday, May 27, 2008 10:56 PM by ScottGu's Blog em Português

Hoje pela manhã nós lançamos a Preview 3 do framework ASP.NET MVC. Eu escrevi em detalhes no mês passado

# First thoughts on ASP.NET MVC Preview 3 | Aaron Lerch

Tuesday, May 27, 2008 10:57 PM by First thoughts on ASP.NET MVC Preview 3 | Aaron Lerch

Pingback from  First thoughts on ASP.NET MVC Preview 3 | Aaron Lerch

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 11:00 PM by Juliano Oliveira

Scott,

Very good!!! I am always on my blog disclosed the news of ASP.NET MVC here in Brazil.

Great job of the whole team!

Bra zillll... zilll... zill... zil

:)

[]´s

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 11:12 PM by pure.krome

Guru Gu wins again!

thanks heaps to all the people working on ASP.NET MVC! We all just can't get enough of it and appreciate everything you guys and gals are doing.

3 Cheers and can't wait for more.

now, to update my existing sites :)

# re: ASP.NET MVC Preview 3 Release

Tuesday, May 27, 2008 11:56 PM by albertpascual

This is the best release yet! I believe that was genius from you to give a job to Phil to work in open source. I wonder what is Haak coing to work next! I am guessing in another open source? May I ask for a micro blogging engine? ;-)

Cheers

Al

http://geotwitter.net

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:15 AM by ScottGu

Hi Jim,

>>>>>>> Quick question of unit testing controller actions without mocking.  Can you describe how you would test actions that except POST data?  For example, an Authenticate action that accepts a username and password.

There are a couple of ways you could handle this.  If it is a form post scenario where you are submitting a username/password, you could just handle these as arguments to the action method.  For example:

public object Login(string username, string password)

{

   // check for login here...

}

You wouldn't need to-do anything special to test this scenario (just pass the parameters directly).

Now, in my scenarios you might want to work with the Request or Response objects directly within your action method.  In scenarios like this you'll want to "Mock" a fake request/response object that you set on the Controller.  You can do this with ASP.NET MVC because the request/response intrinsics it uses are interface based and allow test implementation to be assigned.

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:20 AM by ScottGu

Hi Joseph,

>>>>>>> Why are the form controls not strongly typed?  I feel like something like Html.TextBox(model=>model.FieldName); should be possible. Or maybe something with the form...

Some of the form controls (like the form element) support strongly-typed generics/lambda based usage.  We don't have a strongly typed TextBox and others just yet (although in theory they could be built).  Mainly this is because Html.TextBox("ProductName") often seems conceptually simpler than Html.TextBox<Product>(product, p=>p.ProductName)

Thanks,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:21 AM by Torkel

Regarding ajax helpers, are there any plans for making the underlying javascript framework pluggable? So you can use JQuery or Prototype for example?

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:21 AM by ScottGu

Hi Anthony,

>>>>>> Url Routing replace Url Rewritter?

URL Routing is a little different than the URL Rewritter class (and is much, much richer).  In the Url rewriter scenario you are taking one URL and transforming it into another that is ultimately executed.  With URL routing you skip this transform step and instead route a URL directly to code to run.  This can sometimes make it easier to control the URLs you want.

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:23 AM by ScottGu

Hi EricTN,

>>>>>>> Hi Scott!  Going forward, would ASP.NET MVC also support the ability to use an RIA front-end like Silverlight with MVC?  If an RIA front-end was used as the View, how could we pass ViewData from the Controller to it?

This is a scenario we are thinking about.  Starting with today's Preview 3 release we do have the ability to return JSON based objects to a client.  Silverlight clients could use this to retrieve and send data back and forth to Controller classes on the server.

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:25 AM by ScottGu

Hi Dominic,

>>>>>>> I'm looking forward to how you end up implementing the Html Form Validation Helpers, as this is an area I am still unsure on how to implement properly without the ASP.NET Form PostBack/ViewState safety net. But that won't be for another release, do you have a timeframe for release 4, and will the Validation Helpers be part of it?

Hopefully the validation helpers will show up in the next refresh drop in a few weeks.  One of the things that will be nice about them is that they'll allow you to store your validation rules in your data model objects - and not have to write validation rules within the Controller or View itself.  This makes validation very powerful - since you can change a rule in one place and have all of the UI and Controllers respect them.  I'll blog more details about how this works once it is available.

Hope this helps,

Scott  

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:27 AM by ScottGu

Hi Clashfan,

>>>>>>> Just found out about asp.net mvc today. Looks really cool. It seems like it's based alot on Rails, is this true?

ASP.NET MVC uses concepts from a lot of existing web based mvc frameworks - including Tapestry, Rails, Django and more.  It also obviously has a lot of goodness from existing ASP.NET, plus a few extra new innovations added as well.  

We hope it provides a nice mix and integration of a lot of good ideas, and contributes some of its own. :-)

Thanks,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:27 AM by ScottGu

Hi Erik,

>>>>>>> So how does this relese play with SP1?

This release will work with both .NET 3.5 as well as .NET 3.5 SP1 (and VS 2008 SP1).

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:28 AM by ScottGu

Hi Padgett,

>>>>>> One question:  In preview 2 you couldn’t overload action methods, will this change?

Good question - I need to check with the team to see if overloaded action methods are supported yet.  I don't think they are yet though.

Thanks,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:30 AM by ScottGu

Hi Torkel,

>>>>>>> Regarding ajax helpers, are there any plans for making the underlying javascript framework pluggable? So you can use JQuery or Prototype for example?

Yes - that is something we are looking at hopefully enabling.  You'll definitely be able to use JQuery or Prototype with ASP.NET MVC.  What isn't clear yet is whether you can swap out our helper methods for alternative implementations.  You will ceretainly be able to add your own to the existing ones though.

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:30 AM by ScottGu

Hi BenB,

>>>>>> Does it play well with the SP1 Beta?

Yes - I'm using SP1 Beta on my machine and ASP.NET MVC Preview 3 works great with it.

Thanks,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:31 AM by ScottGu

Hi Shiju,

>>>>>>> Has this version support VWD express 2008?

Yes - ASP.NET MVC Preview 3 will work with VWD Express 2008 as long as you have SP1 Beta installed (since that is the version that added class library and web application project support - which MVC requires).

Hope this helps,

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 1:40 AM by ScottGu

Hi Paul,

>>>>>>>> This is looking really good - I like the testable changes to the Action Result.  Question... I may be off track a bit but is there an easy way for me (in a unit test for example) to test the "view output" *given* a set of view data. e.g. I create some known view data such as page title, product list etc and push that into the view render engine giving me a string (what is ultimately sent to the browser). I then want to be able to perform asserts etc on the string to look for certain data (or the absense of it).

Right now it isn't super easy to-do this using the built-in .aspx view engine.  This is because it requires running in an ASP.NET app domain for things like compilation, etc.  Note that the Controller/Routes testing in ASP.NET MVC can just be done inside a class library unit test project - so doesn't have this issue.

There are other view engines that you can use (NVelocity, NHaml, etc) that I think might allow you to more easily test the view output directly without having to spin up ASP.NET to-do so.

I personally have gone back and forth on the usefulness of doing assert based testing on HTML content output.  It sounds good, and I think for some scenarios might good sense.  But one challange with HTML is that it is unfortunately easy to break (misplaced tag, CSS rule that doesn't work with a specific browser, slow loading Javascript library reference, conflicting Javascript code, etc).  If your test simply asserts for output tags/content it will not detect these types of issues - and so you can find yourself missing issues even though you have 100s of unit tests in theory testing the view.  A better approach might be to investigate doing browser based verification of the view (using something like Watin).  This is more expensive to write/run, but ultimately might provide a better return on investment since it will catch many more issues.

Note that regardless of what you use to test the view, I'd definitely still recommend writing separate unit tests for your controllers.  There is a ton of value in unit testing these - even if you end up doing end to end functional verification as well.

>>>>>>>> Even better, in the designer having the same pricipal for the preview mode saving the whole cycle of building/running the site to check changes to the rendered view.

That is a really cool idea.  I need to think more about how one could go about implementing this, but it is a really nice concept.

Thanks!

Scott

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 2:38 AM by Miguel Madero

Hi Paul,

If you have Team Suite or VSTS Tester Edition you could use Web Tests, record a test and add assertions to verify that either certain HTML Headers are included, that certain tags have a particular value for an attribute and stuff like that. Is a really powerful testing engine. Is not unit testing, but can be an alternative solution.

I know you were talking about testing the view in isolation. It probably wont be that hard to hook dummy controllers with actions that simply set the ViewData you want to test your View with. The cool part is that you can also use the same kind of Web Tests to test the rendering, do end to end functional verification and load testing.

The bad part is you need one of the mentioned VS Team System SKUs. A friendo of me told me about an open source product that does something similar, if you need it I can ask for the name. I know it's not integrated with VS, but finally it's for web testing.

I have not gotten to deep into this MVC Framwork, but it might be possible to swap the implementation of the controllers and their actions at Design Time for one that only set hard coded ViewData, but at runtime it would use the real controller. Anyway you would still have to compile the dummy controller and recompile everytime you change it. Obviously there could be a better solution to this problem, probably setting ViewData in the actual view. I dunno. Silverlight uses some special tags for design purposes (that are only support in blend for now and not VS 08), something like that would be useful.

# ASP.NET MVC Preview 3

Wednesday, May 28, 2008 3:36 AM by ModernIT

ASP.NET MVC Preview 3

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 3:38 AM by Mike

>>>>>> URL Routing is a little different than the URL Rewritter class (and is much, much richer).  In the Url rewriter scenario you are taking one URL and transforming it into another that is ultimately executed.  With URL routing you skip this transform step and instead route a URL directly to code to run.

But the url routing module is now released separate from MVC, so it can be used with web forms right? But then you don't have controllers, you just have aspx pages. How is the url routing valuable for web forms?

And another question: are there any improvements for rendering components (sort of partial views with their own controller)?

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 3:40 AM by Mike

Hi Scott

Your blog posts are always really great, but maybe you could put the date of the post at the top of the post? If I come to your blog from a link elsewhere, and you begin by saying "This morning we...", it's not clear whether or not it's current, and it would be nice not to have to scroll down to the first comment to find out how old the post is.

Thanks for the great posts!

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 3:44 AM by Paul Kinlan

Hi Scott,

It looks good so far, one of the things that I was toying with in the previous preview was asynchronously starting my business logic from the controller, then when completed in the call back call RenderView.  I never got around to trying it so I don't know if it would work, but looking at the required "return ActionResult", the results of our model queries i.e. the business logic will have to be on the same thread as the call to the controller, thus no longer allowing us to asynchronously process our business logic.  I won't be able to process the view rendering code asynchronously any more.

Kind Regards,

Paul

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 3:51 AM by Erik

Scott,

  Thanks for all your responses.  One more question.  Currently if your Controller method Properties are populated from a form, you can not have the strongly typed action links for your form.  Is there anyway to indicate to the URL builder that certain parameters should not be used when searching the out bound routing for a match (because they will be loaded from the form?)  or conversely is there a way to Indicate in a route possibly in the defaults that certain parameters are populated by the Request.x?  

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 3:57 AM by Miguel Madero

Scott:

I have been working with Rails for a while lately, just to learn a new language/platform. I know you guys took concepts of different MVC Framworks. I've never used Django or Tapestry, but it's great than this one one maps so closely to something I'm already familiar, but are more likely to use in a real project.

I have a few points to mention as a comparisson. Not trying to do a which fx is better (I will leave that for the RoR guys) rather to clarify a few points or to be used as suggestions.

Validation helpers would be something similar to what we have in ActiveRecord in Rails? I guess that wont be that hard to implement, but it would be better to have it out of the box with the Framework. I was thinking about doing extension method so we wont need that our Model extends a particular class to use the validation methods. Also CSLA has a nice validation stack, not specially suited for web environments (I feel), but some concepts might be useful, specially how they work with the Error Provider, altough I like the Html Helpers in Rails for displaying erros a better solution (like Html Helpers here).

Caching in rails can be made at an action level? I know we have a Cache object and Page level caching in ASP.NET, but I'm not sure how easy or if possible would be to have action level caching.

Rails has a Flash object, useful to share data between controllers/actions after redirects. Is there something similar here?

Rails have the concept of filters and verifications. These are used to execute code before or after a method or to set rules to certain actions. For example to check for the existence of a cookie or a session value and if it doesnt exist redirect it to some other action could easily be done adding a verification instead of calling a method to do this in every action we need it to. Filters are basically a methods that gets executed before/after the specified actions. I see the Controller class in this MVC Fx has virtual methods OnPreAction and OnPostAction. We can do similar stuff there, but what I like about the Rails approach is that instead of overriding a method on the base class, we will add a filter that will be called only for the *specified actions. These will allow us to define several filters and avoid a bunch of if/else code on our overrriden method.

Rails has a concept of Helpers, you can define them at the Controller or Application level and simply use those methods inside the Views. These can be sexyly done due to Ruby's being a dynamic language. I'm not sure if this could be done, but it would be nice to have access to this helper as a way to reuse code between different views

Well its getting late, I'm sure the comparisson could go on and on, but it's time to go.

In another topic, I know it's only a sample, but in your controllers (and also other samples) I have seen they instantiate the DataContext in the declaration and they never call its dispose method. How is the controller life cycle? Do we have one instance per request? If so, do local variables will get automatically disposed or we shall take care of this?

Yet another topic, can we use the ViewData set in a controller inside a UserControl?

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 4:09 AM by Ladislav

Hi Scott,

today I have to use the Html helpers. Is your team plannning support controls as in Web Forms?

Regards,

Ladislav

# Microsoft ASP.NEt MVC Preview 3 Announced

Wednesday, May 28, 2008 4:21 AM by Guru Stop

Scoot Guthrie's Announcement (With detailed walkthrough) Scott Hanselman's Announcement (With note on

# ASP.NET MVC의 3번째 프리뷰

Wednesday, May 28, 2008 5:27 AM by bkchung's WebLog

ASP.NET MVC Preview 3 Release - ScottGu's Blog (소식) Download details: ASP.NET MVC Preview 3 (다운로드) ASP.NET

# ASP.NET MVC Preview 3

Wednesday, May 28, 2008 5:28 AM by どっとねっとふぁんBlog

ASP.NET MVC Preview 3がでてきましたね セットアップ用パッケージ ソースコード ScottGu's Blog - ASP.NET MVC Preview 3 Release...

# ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 5:32 AM by Сергей Лутай

27 марта был выпущен Preview 3 of the ASP.NET MVC framework. Он включает пачку исправлений и улучшений.

# Rilasciato ASP.NET MVC P3

Wednesday, May 28, 2008 5:42 AM by FoxyBlog

Rilasciato ASP.NET MVC P3

# ASP.NET Framework MVC : Preview 3 disponible

Wednesday, May 28, 2008 5:46 AM by Blog-Microsoft.fr

ASP.NET Framework MVC : Preview 3 disponible

# ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 5:55 AM by Response.Write(

ASP.NET MVC Preview 3 Release

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 8:14 AM by Curious

Just curious, but why are the routes configured in code, versus defining a new declarative section in the web.config?

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 8:28 AM by Dan

@ Steven Tuesday, May 27, 2008 4:47 PM

I believe the color scheme he is using is called ZenBurn (www.codinghorror.com/.../000682.html)

# Late May goodies on Microsoft blogs &laquo; Consulting in Austin

Pingback from  Late May goodies on Microsoft blogs &laquo; Consulting in Austin

# Visual Studio Links #33

Wednesday, May 28, 2008 11:46 AM by Visual Studio Hacks

My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. Scott Guthrie announced the availability of ASP.NET MVC Preview 3 . The release was also mentioned by Phil Haack and Scott Hanselman

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 11:48 AM by Albert

Thanks you for your framework, but I have some problems with running assemblies on Linux with Mono. I have not enought money to by Windows&

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 12:48 PM by Craig Lebowitz

Scott thanks so much for the work on this and the lucid description.  I feel strongly that Mvc framework is easier to understand for new web developers than web forms.   Here's wishing that you and your team keep up the hard work

# re: ASP.NET MVC Preview 3 Release

Wednesday, May 28, 2008 2:01 PM by Jay

Any talk about a CodePlex tool to port Monorail apps to MS MVC?

# re: ASP.NET MVC Preview 3 Release </