FubuMVC Routing – No Strings Attached

Recently I’ve stumbled upon FubuMVC, and thought I should have a go at it, see what can you do with it, and more importantly see how other implementations of the MVC pattern work. After following the HelloWorld in Fubu steps, I felt I really like what I see, and thought I should try and pick it up, blogging on it on my way… If everything would work out nicely, I’m hoping to write my own site with Fubu, and share with others my experience with it 🙂

So the first thing I wanted to have a look at was the way they map (or register) their routes in Fubu, the way we in MVC do

routes.MapRoute(
 "Default", // Route name
 "{controller}/{action}/{id}", // URL with parameters
 new {controller = "Home", action = "Index", id = ""} // Parameter defaults
);

And lo and behold, Jeremy Miller has posted about the subject. Now, I really like the fact that you can simply have a [RouteInput] attribute on your InputModel property, and that’s all it takes to tell the URL to end with “/{Id}”; that way, if you have the IputModel and the controller action

public class ProductsInputModel
 {
 [RouteInput]
 public int Page { get; set; }

 public ProductsInputModel(int page)
 {
 Page = page;
}
}

public class ProductsController
{

public ProductsViewModel List(ProductsInputModel model)
 {
//use model.Page to get your products list of page number X
}

}

then the url /products/List/4 will get you to the 4th page of your products list.

This, by the way, could be also achieved with the QueryString attribute, which as its name suggests, would put this data in your url as a query string like so: /products/List?Page=4

However, using attributes should come only after the convention (that is for exceptional occasions), and that’s something I still need to figure out. Doh’!

Now, what Jeremy was saying in his post (in a nutshell), is that the Fubu equivalent to ASP.NET MVC

Html.ActionLink("ActionName", "ControllerName", routeObjects)

uses no strings whatsoever, but simply uses the conventions. If we use an input model per action, we simply call

UrlRegistry.UrlFor(new ProductsInputModel(4)); 

How cool is that?? Working with ASP.NET MVC I can definitely say that this approach could have made a HUGE difference. One of the things I dread the most is renaming an action name or a controller.

Advertisements
Explore posts in the same categories: Fubu, MVC

Tags:

You can comment below, or link to this permanent URL from your own site.

One Comment on “FubuMVC Routing – No Strings Attached”


  1. […] Notes.Net Personal notes on software development (in France) « FubuMVC Routing – No Strings Attached […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: