Bronzato
Bronzato

Reputation: 9332

Prevent spaces in URL showed like %20

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.

Upvotes: 3

Views: 2378

Answers (1)

rouen
rouen

Reputation: 5124

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?

Upvotes: 2

Related Questions