views:

275

answers:

3

All my dynamically generated action links etc. are creating links like /Account/Setup. It looks strange.

I'd like all my links to be lowercase (meaning /account/setup). Any way to do this?

+3  A: 

Take a look at http://goneale.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/. You can find more information in another stackoverflow at http://stackoverflow.com/questions/878578/how-can-i-have-lowercase-routes-in-asp-net-mvc.

The other posts thus far have not tackled the scenario where you navigate to the root of your web directory. If you have a mapping that directs to the HomeController Index action, you would like the following URL to appear:

mysite/home/ or even mysite/home/index

No amount of Html helper function usage will change the fact that, by default, the following will be shown in the browser location bar:

mysite/Home or mysite/Home/Index

David Andres
A: 

Write an extension method for Html:

public static class MyHtmlExtensions
{
    public static string LowerActionLink(this HtmlHelper htmlHelper,someargs)
    {
        return String.ToLowerInvariant(htmlHelper.ActionLink(someArgs));
    }
}

Then use Html.LowerActionLink instead of Html.ActionLink

spender
Are the routes not case sensitive, then?
Neil Barnwell
I think not, otherwise I'm in big trouble.
spender
Ah... perhaps you might want to preserve some case in the later parts of the route. More judicious use of ToLower in the extension method might be advised
spender
Scratch all of that. In all but the simplest of cases, I don't think doing this is such a good idea, but am leaving it up in case it fits OPs needs.
spender
A: 

Just use

<%= Html.ActionLink("my text", "setup", "account") %>

instead of

<%= Html.ActionLink("my text", "Setup", "Account") %>

Try to point your browser to a lowcase action: it works.

giorgian
I tried this; it doesn't work unfortunately.
Alex