在Sam Saffron 的这篇文章中,他提到 Stack Overflow 的路由如下所示:
questions/{id}/{title?}
那是错字吗?这个问号有什么作用?
来自http://maproutes.codeplex.com/:
[Url("store/{category?}")]
public ActionResult Products(string category)
{
return View();
}
“?” 参数末尾的符号
{category?}
表示它是可选的。UrlParameter.Optional
将是它的默认值。
StackOverflow 使用基于属性的路由,所以我猜问号将该路由参数标记为可选。