Question

i have set up simple paging system in my app that is using the idea from nerddinner tutorial, using the paginated list class:

   public class PaginatedList<T> : List<T>    {
        public int PageIndex {}
        public int PageSize {}
        public int TotalCount {}
        public int TotalPages {}

        public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize){}

        public bool HasPreviousPage {}

        public bool HasNextPage {}  }

The paging works, and i am using it to get the long tables from the database via LINQ2SQL, as in this controller action:

  public ActionResult Index(int page=0)
    {
        const int pageSize = 10;

        var source = repo.SvaMjesta();
        var paginatedList = new PaginatedList<Mjesto>(source, page, pageSize);

        return View(paginatedList);
    }

The paging works fine, i can get to any page as long as i am using query type o URL: /Admin/Mjesta?page=2
That is something i wish to avoid, and would like to use simple URL like: /Admin/Mjesta/Page/2

To that purpose i have made this entry in my AdminAreaRegistration.cs

       context.MapRoute(
            "pMjesta",
            "Admin/Mjesta/Page/{page}",
            new {controller = "Mjesta", action = "Index"});

But when i try to access URL such as /Admin/Mjesta/Page/2 , it still throws me a 404 error.

My idea was to build some sort of general paging entry in MapRouting at first, so i can use the same partial view to render paging controls with every list where i have such need, but as i couldn't make it work i have tried this more specific approach, but i am still not able to get the controller to react to this URL request.

Any ideas and/or suggestions please?

Was it helpful?

Solution

Do you have other routes for that area that the url could be matching?

For instance, if you still have the default area route:

context.MapRoute(
    "DefaultAreaRoute",
    "Admin/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = Url.Optional });

and it is listed before your new route, your preferred url will match and use this route first.

OTHER TIPS

   context.MapRoute(
        "pMjesta",
        "Admin/Mjesta/Page/{page}",
        new {controller = "Mjesta", action = "Index", page = "{page}"});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top