eWorld.UI - Matt Hawley

Ramblings of Matt

ASP.NET MVC Preview 4 New Finds

July 17, 2008 00:49 by matthaw

So I've been checking over the source code for the latest ASP.NET MVC P4 release out on CodePlex, and have found some very interesting things.

 1. There's a variant codebase that is very similar to my RedirectToAction via Lambda expressions contained within the Futures/MvcFutures/Internal directory, "ExpressionHelper.cs". With this futures drop, the call will return a RouteValueDictionary, in which you turn around and call RedirectToRoute. In my version, of RedirectToAction, this is all taken care of for you, as well as it supports not having to explicitly give the type of your controller. Either way, here's the example on how to use this if you prefer:

   1:  using Microsoft.Web.Mvc.Internal;
   2:  using System.Web.Routing;
   3:   
   4:  public class HomeController : Controller
   5:  {
   6:     public ActionResult Index()
   7:     {
   8:        return View();
   9:     }
  10:   
  11:     public ActionResult DoRedirect()
  12:     {
  13:        RouteValueDictionary values = 
  14:           ExpressionHelper.GetRouteValuesFromExpression<HomeController>(c => c.Index());
  15:        return RedirectToRoute(values);
  16:     }
  17:  }

2. The RedirectToAction bug I blogged about has been fixed.

3. They've introduced a helper extension method (MvcControlDataBinder.SourceToDictionary) to convert data sources to a dictionary of values. The supported data source types include

  1. DataSet
  2. DataTable
  3. IDataReader
  4. IList
  5. Array
  6. IQueryable
  7. IEnumerable

Below is an example on how to use this method. While I would never use this to convert a List of models normally, I could see where if you simply need to get truncated key/value list of data with various other sources like IDataReader or IQueryable, this would be beneficial.

   1:  public ActionResult Products()
   2:  {
   3:      List<Product> products = new List<Product>()
   4:      {
   5:          new Product(1, "16 Speed", 499.99m),
   6:          new Product(2, "24 Speed", 699.99m)
   7:      };
   8:   
   9:      Dictionary<object, object> data = 
  10:          MvcControlDataBinder.SourceToDictionary(products, "Id", "Name");
  11:      ViewData["Data"] = data;
  12:   
  13:      return View();
  14:  }

4. The new Ajax support. I'm not going to detail this as Scott Hanselman's post covered a good example and ScottGu will eventually give Part 2 which will be very detailed.

5. As ScottGu already indicated, the Mvc Framework comes with a bunch of new Action Filters, including

  1. AuthorizeAttribute - which uses the membership framework for user authentication and user & role based security.
  2. HandleErrorAttribute - which will enable you to handle exceptions that occur by rendering a specific view when an error occurs. This is equitable to the catch-all error page.
  3. OutputCacheAttribute - Yes, this is what it says it is. Think ASP.NET output caching, and thats what this is.

6. TempData is now "testing friendly"! Well, right out of the box now, that is. They've introduced a new interface ITempDataProvider (and subsequent SessionStateTempDataProvider) that will only be used only when Execute is called from the Controller. The reason TempData is now tester friendly, is that by default it uses TempDataDictionary as a backing field, and Execute will Load/Save from the TempDataProvider set to/from TempData.

kick it on DotNetKicks.com


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

July 17. 2008 14:53

Pingback from weblogs.asp.net

ASP.NET MVC Preview 4 Finds - eWorld.UI - Matt Hawley

weblogs.asp.net

July 18. 2008 05:35

Is the Html.SubmitButton helper deprecated?

VB

July 18. 2008 12:53

Pingback from zuhaib.in

Zuhaib | ASP.NET MVC Preview 4 Released

zuhaib.in

July 20. 2008 02:35

@VB,

Take a look in Microsoft.Web.Mvc.dll (which is the Futures project). I believe Html.SubmitButton is there now.

Brad Wilson

July 20. 2008 03:05

Thanks Brad - I found in there.... I just wish all these details were included in the release notes

VB

April 21. 2009 16:59

Thanks friends- I found in there.... I just wish all these details were included in the release notes

saç ektirme

April 24. 2009 10:09

very helpful info

Call Center Software

May 29. 2009 10:54

very nices article
http://www.nakliyatfirmalari.org ankara nakliye
http://www.ankara-nakliye.com ankara evden eve nakliyat
http://www.asansorluevdenevenakliyat.com asansörlü evden eve nakliyat
http://www.evdenevenakliyecilik.com evden eve nakliyat

nakliye ankara

May 31. 2009 14:32

Great thanks

yazılım

June 23. 2009 02:51

thanks great post

earn college degree

June 23. 2009 03:48

I just wish all these details were included in the release notes

saç ektirme

affordable degrees

June 23. 2009 03:48

thanks for the information

earn a college degree online

June 23. 2009 03:49

Preview 4 Finds - eWorld.UI - Matt Hawley

online counseling degrees

June 30. 2009 08:45

nakliyat evden eve nakliyat nakliye taşımacılık

sarac

July 2. 2009 09:14

Thanks for sharing these finds.

Affordable crm solutions

July 3. 2009 04:48

thanks for this nice post

Indianapolis web design

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 3. 2009 21:45



Copyright © 2000 - 2009 , Excentrics World