Tuesday, May 27, 2008

Mvc.Net mapping / Preview 3

I said in an earlier post that I would like to have a mapping feature so that you can indicate actions via configuration rather than code. My tenative plan was to create a new subclass of Controller called MapController. It would have a method like

MapAction(string actionName)

In my login example, I'd change my action to:

MapAction("Membership.LoginSuccess");
which would redirect to the Home

MapAction.("Membership.LoginFailed")
which would render the LoginFailed view.

MapAction would do a lookup from the configuration store then do a render or RedirectToAction.

Preview 3 actually makes this a lot easier, because the acton methods now return an ActionResult object.

The subclasses of ActionResult (that I can find) are:
- ContentResult
- EmptyResult ?? (do nothing?)
- JSonResult
- RedirectResult
- RedirectToRouteResult
- ViewResult

So far, I've used implicitly used RedirectToRouteResult and ViewResult. (Controller has a RedirectToAction method and a View method which genereates the appropriate result object automatically).

This means that all I'd really need to do is create the appropriate type of ActionResult object and populate it from configuration. The saving is that the objects already exist; in Preview2, I would've had to create my own objects. (I'm glad I didn't waste time on it, then).

Now, I'd do:
return MapAction("LoginMembership.Success")

It'd be neat, but I'm not in a huge rush to do it. We'll see if it magically appears.

No comments: