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;
4: public class HomeController : Controller
6: public ActionResult Index()
8: return View();
11: public ActionResult DoRedirect()
13: RouteValueDictionary values =
14: ExpressionHelper.GetRouteValuesFromExpression<HomeController>(c => c.Index());
15: return RedirectToRoute(values);
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
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()
3: List<Product> products = new List<Product>()
5: new Product(1, "16 Speed", 499.99m),
6: new Product(2, "24 Speed", 699.99m)
9: Dictionary<object, object> data =
10: MvcControlDataBinder.SourceToDictionary(products, "Id", "Name");
11: ViewData["Data"] = data;
13: return View();
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
- AuthorizeAttribute - which uses the membership framework for user authentication and user & role based security.
- 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.
- 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.