An awesome routing engine for ASP.NET MVC 3 and 4
UrlHelperextension methods that allows to easily get the target URLs for your SEO routes by way of strongly typed lambda expressions (no more action names strings). This way, you can wipe out the number of bugs related to the way you build your URLs and, at the same time, make the process of renaming and refactoring for your action methods a quick and safe task.
UrlHelperclass (generally available inside MVC actions and controllers by way of the
Urlcontextual property), along with a lambda expression which specifies the eventual parameter values. The
RouteUrlis a generic method and requires you to pass the type of the controller you are interested in.
RouteUrlmethod is called inside a Razor view, in order to retrieve the URL for a SEO action:
@using Cobisi.Web.MvcExtensions <h1>hello, world</h1> <a href="@( Url.RouteUrl<MyController>(c => c.Foo(MyEnum.SecondUglyValue)) )">Click me, please</a>
RouteUrlextension method being also available within your controllers, SEO Extensions also comes with handy extensions methods for the
Controllerclass itself. In fact, the
RedirectToDeclarativeRoutemethod allows to easily retrieve an
ActionResultinstance which can be used to redirect to a specific declarative route, identified by a lambda expression.
AddItemToCartaction method one of the previously defined controllers is updated to redirect to another action method, in the same controller. Since the
RedirectToDeclarativeRoutealso accepts a generic argument specifying the target controller class, the same technique can be applied for external controllers too.
[Route.Action("~/cart/add")] public ActionResult AddItemToCart( [Route.Param(Constraint = @"part-\d{3}")] string item ) { // TODO: Update the shopping cart as requested return this.RedirectToDeclarativeRoute(c => c.ShowCartSummary()); } [Route.Action("~/cart/summary")] public ActionResult ShowCartSummary() { return Content("Thanks for your order, dude"); }