【发布时间】:2012-01-26 03:55:33
【问题描述】:
您好,我注册的路线如下:-
routes.MapLocalizedRoute("Category",
"{SeName}-c{categoryId}",
new { controller = "Catalog", action = "Category", SeName = UrlParameter.Optional },
new { categoryId = @"\d+", SeName = @"([-\w+]+(/[-\w+]+)*)+" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("CategoryWithManufacture",
"{SeName}-d{categoryId}/{ManufactureName}/{Color}",
new { controller = "Catalog", action = "Category", SeName = UrlParameter.Optional, Color = UrlParameter.Optional },
new { categoryId = @"\d+", SeName = @"([-\w+]+(/[-\w+]+)*)+", ManufactureName = @"([-\w+]+(/[-\w+]+)*)+", Color = @"([-\w+]+(/[-\w+]+)*)+" },
new[] { "Nop.Web.Controllers" });
我们生成如下:-
href="@Url.RouteUrl("CategoryWithManufacture", new { categoryId = currentCategoryId, SeName = seName, ManufactureName = manufacturerFilterItem.Name, Color = color })"
href="@Url.RouteUrl("Category", new { categoryId = currentCategoryId, SeName = seName})"
有一种方法可以直接将值分配给第二个参数“Color”,而无需将值分配给“ManufactureName”。表示:-(使用 CategoryWithManufacture Route)
/gloves-d18/red (second parameter)
/gloves-d18/hp/red (first and second both)
我已经通过将制造名称和颜色都设为可选来尝试这些,但是当我们将值分配给第一个参数而不是第二个参数时,它可以工作。但是我们不是先给第二个参数赋值,那就不行了。
请给我推荐可用的链接或示例代码。
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-2 razor