3

I would like to display nice URL in address bar and avoid spaces to display like %20

Here is an example:

enter image description here

Is it possible to replace these spaces with a dash ?

Something like: /BANQUE/International-Ledger

Maybe something to do in the routing ?

Thanks.

Bronzato
  • 9,438
  • 29
  • 120
  • 212
  • Check it out http://stackoverflow.com/questions/2174820/how-to-add-page-title-in-url-in-asp-net-mvc-url-generation – m3kh Nov 13 '11 at 08:40
  • 1
    In it's simplest form, couldn't you just name your controllers/actions with the dashes in the title instead of space? – dougajmcdonald Nov 13 '11 at 08:45

1 Answers1

2

You dont want to replace spaces in generated route, you want to not generate them in the first place.

What is your "International Ledger" ? If it is action, then use [ActionName("International-Ledger")]

If it is some kind of product or category of product, is it good practice dont use product name for URL, but some "token" generated from name, for example with regex, replacing spaces with dashes, special letters with theirs basic alphabet variants, and maybe some unique identifier to prevent conflicts of products with the same name.

see How can I create a SEO friendly dash-delimited url from a string?

Community
  • 1
  • 1
rouen
  • 5,003
  • 2
  • 25
  • 48