【发布时间】:2015-10-15 22:22:52
【问题描述】:
我已经用 MVC SiteMapProvider 搞砸了一段时间,我很喜欢它。我正在建立一个电子商务网站,到目前为止,它在我的开发过程中运行良好。
我似乎无法解决的一个问题是如何让 dynamicNode 在第一级工作。
类似这样的:
www.mysite.com/{type}/{category}/{filter}
只有 3 种类型,所以现在我只有 3 个以该类型命名的控制器,它们都使用相同的逻辑和视图模型,这对于未来的可维护性来说并不是一个理想的设置。我的 routeConfig 包括 3 条这样的路线。
routes.MapRoute(
name: "Hardscape",
url: "hardscape-products/{category}/{filter}",
defaults: new { controller = "Products", action = "Index", category = UrlParameter.Optional, filter = UrlParameter.Optional},
namespaces: new[] { "MyApp.Web.Controllers" }
);
routes.MapRoute(
name: "Masonry",
url: "masonry-products/{category}/{filter}",
defaults: new { controller = "Products", action = "Index", category = UrlParameter.Optional, filter = UrlParameter.Optional},
namespaces: new[] { "MyApp.Web.Controllers" }
);
routes.MapRoute(
name: "Landscape",
url: "landscape-products/{category}/{filter}",
defaults: new { controller = "Products", action = "Index", category = UrlParameter.Optional, filter = UrlParameter.Optional},
namespaces: new[] { "MyApp.Web.Controllers" }
);
我尝试过类似的方法,但它返回 404。
routes.MapRoute(
name: "Products",
url: "{productType}/{category}/{filter}",
defaults: new { controller = "Products", action = "Index", productType = UrlParameter.Optional, category = UrlParameter.Optional, filter = UrlParameter.Optional},
namespaces: new[] { "MyApp.Web.Controllers" }
);
我已经能够为我的类别和过滤器参数使用 dynamicNode 在站点地图和菜单中生成我的节点。当我没有静态命名第一级时,只是遇到了第一级的问题
masonry-products/ vs. {productType}/
如果您有解决方案,请告诉我。希望 NightOwl 能加入进来。
【问题讨论】:
-
请从您的标题中删除“已解决”并从您的问题中删除解决方案。如果您自己的解决方案与接受的答案不同,您可以随意将其添加为单独的答案。
-
感谢您的建议。
标签: asp.net-mvc asp.net-mvc-5 mvcsitemapprovider