Abe*_*ler 18 asp.net asp.net-mvc nopcommerce
我想让我的基本URL转到在线商店的特定类别(NopCommerce在线商店,如果这有所不同).该类别的URL是: http://myUrl.com/c/6
在阅读了几篇包括Scott Gutherie 关于MVC路由的帖子后,我想我可以将以下代码添加到我的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" }
);
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我怎样才能完成我想做的事情?
我对MVC的经验很少,所以如果任何一个没有意义,我会道歉.
nat*_*lez 14
看起来像nopcommerce源代码中最有趣的位.默认路由注册为
routes.MapLocalizedRoute("HomePage",
"",
new { controller = "Home", action = "Index"},
new[] { "Nop.Web.Controllers" });
Run Code Online (Sandbox Code Playgroud)
你基本上想要在//register custom routes评论之前首先注册你的默认路线.应该看起来像这样:
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", action = "Category", id = 6 },
new[] { "Nop.Web.Controllers" }
);
routes.MapRoute(
"CustomHome", // Route name
"", // URL with parameters
new { controller = "Catalog", action = "Category", id = 6 },
new[] { "Nop.Web.Controllers" }
);
//register custom routes (plugins, etc)
var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>();
routePublisher.RegisterRoutes(routes);
}
Run Code Online (Sandbox Code Playgroud)
甚至可能不需要第一条路线.我不确定.从未与nopcommerce合作过.
| 归档时间: |
|
| 查看次数: |
53613 次 |
| 最近记录: |