开发者

Improving urls in asp.net mvc2

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([DefaultVa开发者_如何学Golue(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?


Change routes.MapRoute

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜