views:

56

answers:

2

Hi,

My question is simple, how to get an ActionLink to append an / to the end of a link. For some reason our SEO team seem to think this is useful? (anyone? why?) currently ActionLink renders the link as More about vouchers but they would like it to be More about vouchers. Does anyone know how to easily do this without constructing my own element and using Url.Action instead?

Many thanks,

Chris

+1  A: 
<a href="<%= Url.Action ("More", "Vouchers") + "/" %>">More about vouchers</a>
Developer Art
Tried this but it just adds // after the </a>.
Chris Woods
Fixed it, try it now.
Developer Art
Yes this will achieve this but i was hoping there was an easier way still using ActionLink as i will have to change this in about 150+ places !!!
Chris Woods
Then write your own helper that will take the necessary parameters and output a link with the "/" at the end of it.
Developer Art
A: 

You could make an extension method to UrlHelper and use that instead of Action()

public static class UrlHelperExtensions
{
    public static string MyAction(this UrlHelper helper, string action, string controller)
    {
        return helper.Action(action, controller) + "/";
    }
}

Then you can use it like this from your code

<%= Html.ActionLink("More about vouchers", "More", "Vouchers") %>

But i'd really recommend you implement one extension method per action, so you can refer to then like this:

<%= Html.ActionLink("More about vouchers", Url.MoreAboutVouchers()) %>
Kristoffer Deinoff