views:

247

answers:

1

Without creating my own ActionLink HtmlHelper is there a way to force any ActionLinks to be rendered lowercase?

Update: Check out the following links for extending the RouteCollection to add LowecaseRoutes http://www.makiwa.com/index.php/2008/05/31/lowercase-mvc-route-urls/ http://goneale.wordpress.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/

+10  A: 

The best way to handle this, is at the routing level. Force all route paths to be lowercase, and it will properly propagate to your action links etc.

The way I've solved this, is to create a new route class that inherits Route and simply overrides the GetVirtualPath method;

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
    var virtualPath = base.GetVirtualPath(requestContext, values);

    if (virtualPath != null)
        virtualPath.VirtualPath = virtualPath.VirtualPath.ToLowerInvariant();

    return virtualPath;
}

I've also created a few extension methods for RouteCollection to make it easy to use this new route class.

Thomas J
Thanks. As a solution it works. I was hoping there would be a easier (not need to create and use my own Route class) way to do this but have been unable to find one.
Luke Smith