Question

I would like my ASP.NET MVC4 application to only serve the base HTML markup for a specific page, and after that I'm processing everything else on client-side with knockout.js/history.js/AJAX, including the initial page load.

So when someone refers to URL http://example.com/products/list/food/fruits, the MVC router should simply ignore everything what is behind "products/list" and route the request to ProductsController and List action. Then on client-side I will handle the rest and load the requested data accordingly.

I was playing with the route definitions, I tried to completely skip the "products/list" route, I also tried to add a "products/list/*" route, but didn't have success yet.

Was it helpful?

Solution

You can use an asterisk as part of the last variable in a route. For example, when configuring your routes:

routes.MapRoute(
    "ProductRoute",
    "products/list/{*otherArgs}",
    new { controller = "Products", action = "List" });

You can learn more in MSDN's Documentation on routing under the section "Handling a Variable Number of Segments in a URL Pattern"

OTHER TIPS

You will need to create your own route.

Something like this should do the trick:

 routes.MapRoute("Products", "Products/{List}",
            new {controller = "Products", action = "List"}
            );

Note: I´m not sure if the other parameters are required in the route.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top