问题描述
我有一个网站,其中列出了产品类别.我想在路由中定义的类别非常类似于www.domain.com/categoryA.
I have a website that has categories for the products. I wanted to have the categories defined in a route pretty much like www.domain.com/categoryA.
这是我的问题,如果我的数据库中有拳击手套"类别,该如何处理类别名称中的空格?
Here's my problem what if I have category in my database that is 'Boxing Gloves' how do I handle the space in the category name?
推荐答案
您可以将空格编码为%20,但这实际上并不适合使用漂亮的url.我建议您将它们转换为破折号,并在类别名称中禁止使用破折号.您还可以禁用空格并像大多数标记系统一样强制用户使用破折号.
You can have spaces encoded as %20, but that doesn't really make for pretty urls. I'd suggest you convert them to dashes and disallow dashes in category names. You could also disable spaces and force users to use dashes like most tagging systems.
这篇关于带有空格的类别的MVC路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!