【发布时间】:2013-07-26 18:11:08
【问题描述】:
我有一个这样的网站 -
主页 - www.mysite.com。
类别页面 - www.mysite.com/Categories。 (从主页链接)
在“类别”页面上,我有一个类别链接列表。
如果有人选择了一个类别,我想显示这样的 URL -
(选择 CategoryA 后)- www.mysite.com/Categories/CategoryA
(选择 CategoryB 后)- www.mysite.com/Categories/CategoryB
目前,我的网址显示如下 - www.mysite.com/Categories/Index/CategoryA
我有一个HomeController 和一个CategoriesController。 CategoriesController 有一个名为 Index 的 Action,其中不包括一个 Category,它是单词 Index 的来源。
如何去掉Index这个词?
我尝试映射Route,如下所示,但它不起作用 -
routes.MapRoute(
name: "CategoriesPage",
url: "Categories/{id}",
defaults: new { controller = "Categories", action = "Index", id = UrlParameter.Optional }
);
【问题讨论】:
-
谢谢迈克!我最终在其他地方找到了答案。 (见下面我的回答)
标签: asp.net-mvc