Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:34:37+00:00 2026-05-30T23:34:37+00:00

Say I will be passing below URL requests to the routing system, this is

  • 0

Say I will be passing below URL requests to the routing system, this is the longest URL possible.

store/storecontent/pets/cat/food/1

Where “1” is the page number and pets is the rootpointer

Now my route entry looks like so:

    routes.MapRoute(
    "StoreContent", // Route name
    "{controller}/{action}/{rootpointer}/{category}/{category2}/{page}", // URL with parameters
    new { rootpointer = UrlParameter.Optional, category= UrlParameter.Optional, category2 =     UrlParameter.Optional, page = UrlParameter.Optional},
new { controller = "Store", action = "StoreContent" });

My method like so:

public PartialViewResult StoreContent(string rootpointer, string category, string category2, int page) {}

The problem is when I pass a URL like store/storecontent/pets/1 then category gets assigned the “page” value, understandably as page is now positioned in the place of the route segment reserved for category and routing system has no way of telling which value belongs to page and which to category since these are anonymous types.

Is there any way around this, I understand this can be done manually by using catchall and parsing it to extract values, but is there a more graceful solution that does not need any manual intervention ? I could also probably just use something like /page-{page}/ if my URL’s reflect it then routing system should pick-up it’s for the page anonymous type and assign its value correctly to the page parameter on the method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:34:38+00:00Added an answer on May 30, 2026 at 11:34 pm

    This is not the way that routing works

    If you define a route as

    {controller}/{action}/{rootpointer}/{category}/{category2}/{page}
    

    And then access your page using store/storecontent/pets/1 then your route parameters are as follows:

    • controller = store
    • action = storecontent
    • rootpointer = pets
    • category = 1
    • category2 = null
    • page = null

    What you’re trying to do is actually store/storecontent/pets///1 but you can’t provide such URLs

    RESTful?

    This is also not RESTful. Why? Because providing page as part of your URL returns arguably nondeterministic results…

    That’s why paging and sorting should be (in terms of REST) provided as query variables as in store/storecontent/pets?page=1. This would of course work. They become arbitrary variables not related to routing per se. Try if this also works for your route definition because it may as well work, since many of your route segments are optional.

    Possible solution 1

    The possible solution (although I would suggest you keep paging as query variable) would be to define several routes:

    {controller}/{action}/{page}
    {controller}/{action}/{rootpointer}/{page}
    {controller}/{action}/{rootpointer}/{category}/{page}
    {controller}/{action}/{rootpointer}/{category}/{category2}/{page}
    

    each of these would need constraints on page = "\d+" so routing follows along until correct one gets hit.

    Possible solution 2

    By keeping page as a separate query parameter nobody said you can’t define it as part of the defaults:

    routes.MapRoute(
        "Some route",
        "{controller}/{action}/{rootpointer}/{category}/{category2}",
        new {
            rootpointer = UrlParameter.Optional,
            category= UrlParameter.Optional,
            category2 = UrlParameter.Optional,
            page = 1
        }
    );
    

    As you can see I’ve provided a default value for page. I know you’ve set it as optional, but all I’m saying here is that you can provide defaults for non-route related values. Query variables for example.

    Additional observation

    If you provide single value constant constraints for controller and action there’s no need to keep them in route definition as route values the way that you did. Your current route as it’s defined at the moment would be better of as:

    routes.MapRoute(
        "StoreContent", // Route name
        "Store/StoreContent/{rootpointer}/{category}/{category2}/{page}", // URL with parameters
        new {
            controller = "Store",
            action = "StoreContent",
            rootpointer = UrlParameter.Optional,
            category = UrlParameter.Optional,
            category2 = UrlParameter.Optional,
            page = UrlParameter.Optional
        }
        // no need for constraints
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I want a method which will be called like this: tiger =
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
Possible Duplicate: In PHP (>= 5.0), is passing by reference faster? Say I'm dealing
I have seen some instances where people will say you have to use JS
I know it will sound dumb or people will just say: read the documentations
Say you construct an activerecord query that will always just return a single value,
Say you have a variable called hotelPropertyNumber . The contents will always be a
Lets say I have a simple 1D array with 10-20 entries. Some will be
Let's say I have an html form. Each input/select/textarea will have a corresponding <label>
Which ORM will give me compile-tested queries? Is linqtosql compile time tested? Edit: Say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.