0

我想知道如何使用 mvc 5 路由来执行以下场景

我的网址结构

http://www.xx.com/search/1

http://www.xx.com/search/cat/1

http://www.xx.com/search/cat/prod/1

[Route("search/{cat?}/{prod?}/{pageId:int=1}")]
public ActionResult Index(string cat, string prod, int pageId)
4

1 回答 1

2

您可以为您的场景执行以下操作:

[Route("search/{pageId:int=1}")]
[Route("search/{cat}/{pageId:int=1}")] //
[Route("search/{cat}/{prod}/{pageId:int=1}")]
public ActionResult Index(string cat, string prod, int pageId)
{
   ....
}
于 2013-10-29T21:58:57.897 回答