0

Hi I have registered route as below :-

 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" });

We generate these like below :-

 href="@Url.RouteUrl("CategoryWithManufacture", new { categoryId = currentCategoryId, SeName = seName, ManufactureName = manufacturerFilterItem.Name, Color = color })"


 href="@Url.RouteUrl("Category", new { categoryId = currentCategoryId, SeName = seName})"

There is a way to assign value directly to second parameter "Color" without assign value to "ManufactureName". means :- (Using CategoryWithManufacture Route)

/gloves-d18/red  (second parameter)
/gloves-d18/hp/red (first and second both)

I have tried these by making manufactureName & color both optional but when we assign value to first parameter not second it , it work . But we assign value to second parameter not first ,then it is not work .

Please suggest me usable link or sample code.

1 Answer 1

1

Only the last parameter can be optional in a route definition. Given the following url /gloves-d18/red the route engine cannot possible know that red refers here to {Color} and not {ManufactureName}. The only to make this work is to write some constraint for those 2 parts. Right now they both have the exactly same regular expression constraint.

Sign up to request clarification or add additional context in comments.

1 Comment

please suggest me any modification in my route.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.