views:

129

answers:

2

I have a wild card route, but at the same time I want to check for the existance of a page number at the end of the url.

so my url might look like:

www.example.com/category/parentcat/childcat/234

where 234 is the page number.

the route currently looks like:

new Route("category/{*category}

Since its a wild card route, I can't put the page number at the end of the route definition.

What is the best way to handle this?

+1  A: 
ActionResult MyAction(string category)
{
page = category.Split('/').Last();
}

like this?

Alexander Taran
Indeed, once you use a wildcard route parameter segment it's up to the developer to do any additional parsing of the segments.
Eilon
+1  A: 

In addition to my comment on Alexander's post, a different solution to the general problem is to use a query string parameter for the page. In other words, the URLs would look like this:

www.example.com/app/category/subcategory?page=123

Then your action method would take two parameters:

public ActionResult ShowCategory(string category, int? page) {
    ...
}
Eilon