我在GameGold文件夹中有两个文件夹,我想拥有单独的控制器。
文件夹是"硬币"和" pgo"。我已经研究了一点路由,但它们只是真正告诉你如何路由到文件夹或子文件夹,但没有更深入。
我也希望能够转到GoldGold文件夹中的索引。我是ASP.Net和MVC的新手,但不是C#,我只是无法完全绕过路由配置。
routes.MapRoute(
name: "GameGold",
url: "Products/GameGold/{controller}/{action}/{id}",
defaults: new { controller = "Coins", action = "Index" }
);
网址示例:
website.com/Products/GameGold/Coins/Index
website.com/Products/GameGold/Pgo/Index
website.com/Products/GameGold/Index
我希望还包括破折号,因为它们有助于搜索引擎优化。
编辑:
我在下面尝试过这种方法。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "GameGold",
url: "Products/GameGold/{controller}/{action}/{id}",
defaults: new { controller = "Coins", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
现在我得到这个???为什么它会查看视图而不是我在代码中编写的文件夹!!
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Coins/Index.aspx
~/Views/Coins/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Coins/Index.cshtml
~/Views/Coins/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml