views:

33

answers:

1

Improving urls

Currently I have links in the form (displaying product information):

http://localhost:XXXX/Products/?page=1

I want to clean this up into the form:

http://localhost:XXXX/Products/Page1

I think I need to do this with routes.MapRoute, something like so:

routes.MapRoute(null, "/Products/Page{page}", new {controller = "ProductController", action = "Index"});

This was put above the default route (so should override I am led to believe)

The product controller looks like this:

    //
    // GET: /Products/
    public ActionResult Index([DefaultValue(1)] int page)
    {
        var productsToShow = //omitted for simplicity

        var viewModel = new ProductIndexViewModel
                            {
                                ProductList = //omitted for simplicity,
                                PagingInfo = new PagingInfo
                                                 {
                                                     CurrentPage = page,
                                                     ItemsPerPage = PageSize,
                                                     TotalItems = productsToShow.Count()
                                                 }
                            };

        //Passed to view as ViewData.Model (or simply Model)
        return View(viewModel);
    }

What am I doing wrong?

+2  A: 

Change routes.MapRoute

routes.MapRoute(null, "Products/Page{page}", new {controller = "Products", action = "Index"});
Akyegane
Correct - the *Convention* is that all controller classes END with the word `Controller`. As such, the routes then don't need you to add that full word into the route details, as above. So like @Akyegane says, controller = "Products" .. not "ProductsController"
Pure.Krome