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

  • SEARCH
  • Home
  • 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 7907265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:21:13+00:00 2026-06-03T11:21:13+00:00

I have a URL in a Django based web app that looks similar to

  • 0

I have a URL in a Django based web app that looks similar to this:

/market/prices/2011-05-01/min/stocks/msft/dell/appl/

The application is being rewritten in ASP.NET MVC 3. I need to maintain the URL.

The crux of the problem is that I to support the multiple stock ticker symbols separated by forward slashes.

I want a custom route that looks like this:

routes.MapRoute(
    "Stocks",
    "{queryDate}/{minOrMax}/stocks/{listOfStocksSeparatedByForwardSlash}",
    new { controller = "Market", action = "Prices" }
);

The controller would look something like:

public ActionResult Prices(string queryDate, string minOrMax, ICollection<string> listOfStocksSeparatedByForwardSlash) {
    var model = repository.List(queryDate, minOrMax, listOfStocksSeparatedByForwardSlash);
    return View(model );
}

My current solution is as follows:

routes.MapRoute(
    "Stocks",
    "{queryDate}/{minOrMax}/stocks/{*listOfStocksSeparatedByForwardSlash}",
    new { controller = "Market", action = "Prices" }
);

public ActionResult Prices(string queryDate, string minOrMax, string listOfStocksSeparatedByForwardSlash) {
    var list = listOfStocksSeparatedByForwardSlash.Split('/').ToList();
    var model = repository.List(queryDate, minOrMax, list);
    return View(model );
}

Although this works, I’m interested to know if there is a better way to do this?

  • 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-06-03T11:21:18+00:00Added an answer on June 3, 2026 at 11:21 am

    Okay, this is an option, although I think your approach is easier.

    You can provide a RouteHandler attached to a route, like so:

    
    routes.MapRoute(
        name: "Test",
        url: "Test/{someDate}/{*tickerSymbols}",
        defaults: new { controller = "Home", action = "Test" }).RouteHandler = new SlashSeparatedTrailingParametersRouteHandler("tickerSymbols", "tickers");
    

    with the route handler being

    
    public class SlashSeparatedTrailingParametersRouteHandler : IRouteHandler
    {
        private readonly string catchallParameterName;
        private readonly string actionTargetParameter;
    
        public SlashSeparatedTrailingParametersRouteHandler(string catchallParameterName, string actionTargetParameter)
        {
            this.catchallParameterName = catchallParameterName;
            this.actionTargetParameter = actionTargetParameter;
        }
    
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
    
            IRouteHandler handler = new MvcRouteHandler();
            var vals = requestContext.RouteData.Values;
            vals[this.actionTargetParameter] = vals[this.catchallParameterName].ToString().Split('/');
            return handler.GetHttpHandler(requestContext);
        }
    }
    

    If this is your controller action:

    
    [HttpGet]
    public ActionResult Test(DateTime someDate, string[] tickers)
    {
        if (tickers == null)
        {
            throw new ArgumentNullException("tickers");
        }
    
        return Content(string.Format("{0} and {1}", someDate, tickers.Length.ToString(CultureInfo.InvariantCulture)));
    }
    

    and this your post:

    
    http://localhost/Test/12-06-2012/Foo/Bar
    

    then your output is:

    
    12/6/2012 12:00:00 AM and 2
    

    On the elegance this this improves the parameter on the action method at the expense of having to write your own route handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Django view that just returns URL parameters, but if I
I have a text area in a django based website that displays the content
In our web application (django based, with solr backend) we have some checkboxes with
I am having trouble doing a reverse URL lookup for Django-generated feeds. I have
I have a Django project. Given a url, how can I know which view
I currently have a DetailView for Django's built-in User . url( r'^users/(?P<pk>\d+)/$', DetailView.as_view( model
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I have URL like this: http://localhost/PMApp/temp.htm?ProjectID=462 What I need to do is to get
I have a web application which will return a user id based on the
I have a website tracked using Google Analytics. It is a Django-based website, so

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.