MVC Routes, adding a filter to existing page

279 views Asked by At

I have a route:

 context.MapRoute(
            "ISPCCodeSearch_default",
            "OnlineOrder/{controller}/ISPCCodeSearch/{ISPC}",
            new
                {
                    area = "OnlineOrder",
                    controller = "Home",
                    action = "ISPCCodeSearch",
                    ISPC = UrlParameter.Optional,

                });

that brings up a number of products by a product code eg,

OnlineOrder/Home/ISPCCodeSearch/11011/

I want to further filter this by brand by clicking on a filter link on the above page.

OnlineOrder/Home/ISPCCodeSearch/11011/Xerox

How do I generate the links and the route?

<a class=" list-group-item" href='@(Url.Action("BrandFilter", new {brand = item.BrandName}))'>
                    @item.FriendlyBrandName <span class='badge'>@item.BrandItemsCount</span>
                </a>

I have the above code which just gives me :

/BrandFilter/Xerox

I don't know how to implement this.

1

There are 1 answers

2
floatas On BEST ANSWER

You will need to update route:

context.MapRoute(
            "ISPCCodeSearch_default",
            "OnlineOrder/{controller}/ISPCCodeSearch/{ISPC}/{param2}",
            new
                {
                    area = "OnlineOrder",
                    controller = "Home",
                    action = "ISPCCodeSearch",
                    ISPC = UrlParameter.Optional,
                    param2= UrlParameter.Optional,
                });

And for a link, just add another property:

@(Url.Action("BrandFilter", new {brand = item.BrandName, prop2 = item.property2}))