我想让我的基本URL去一个在线商店的特定类别(一个
NopCommerce在线商店,如果这有所作为).该类别的URL为:http://myUrl.com/c/6
在阅读包括Scott Gutherie的帖子about MVC routing在内的几篇帖子后,我以为我可以将以下代码添加到我的Global.ascx.cs文件中:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //register custom routes (plugins,etc) var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); routePublisher.RegisterRoutes(routes); routes.MapRoute( "Default",// Route name "{controller}/{action}/{id}",// URL with parameters new { controller = "Catalog",action = "Category",id = 6 },new[] { "Nop.Web.Controllers" } ); }
但这似乎没有起作用.我该如何完成我想要做的事情?
我对MVC没有什么经验,所以我道歉,如果这没有任何意义.
解决方法
看起来像最有趣的位在nopcommerce源代码中.默认路由注册为
routes.MapLocalizedRoute("HomePage","",new { controller = "Home",action = "Index"},new[] { "Nop.Web.Controllers" });
您将基本上希望先注册默认路由,然后注册自定义路由注释.应该最终看起来像这样:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default",// Route name "{controller}/{action}/{id}",// URL with parameters new { controller = "Catalog",new[] { "Nop.Web.Controllers" } ); routes.MapRoute( "CustomHome",// Route name "",// URL with parameters new { controller = "Catalog",new[] { "Nop.Web.Controllers" } ); //register custom routes (plugins,etc) var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); routePublisher.RegisterRoutes(routes); }
第一条路线甚至不需要.我不确定.从未与nopcommerce合作.