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 481245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:58:30+00:00 2026-05-13T00:58:30+00:00

The recommended approach for passing lists of values as a QueryString is www.site.com/search?value=1&value=2&value=3&value=4 ASP.NET

  • 0

The recommended approach for passing lists of values as a QueryString is

www.site.com/search?value=1&value=2&value=3&value=4

ASP.NET handles this well:

string value = QueryString.Get("value"); // returns "1,2,3,4"

But I can’t figure out a way of passing these values by into RouteData. The obvious approach would be to add

int[] value = {1,2,3,4};

into the RouteData and have super smart MVC sort things out for me. Unfortunately MVC is dump when it comes to passing arrays into RouteData, it basically calls .ToString() adding value=int[] to my QueryString.

I tried adding the values to RouteValueDictionary (but being a dictionary can’t handle this:)

RouteValueDictionary dict = new RouteValueDictionary();
dict.Add("value","1");
dict.Add("value","2"); // Throws Exception (Keys must be unique)

I could try passing values like this:

www.site.com/search?value=1,2,3,4

but this is Encoded to the URL as

www.site.com/search?value=1%2C2%2C3%2C4

I’m not sure if this is a bad thing or not,but it sure looks bad.

So, how do you pass lists of values as RouteData in ASP.NET MVC. Is there any way I can add to MVC to make it handle an int[]? Or is the underlying Dictionary-based data structure a show-stopper for passing lists of values easily to ASP.NET MVC?

  • 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-13T00:58:30+00:00Added an answer on May 13, 2026 at 12:58 am

    I’ve come up with a solution to this myself by making a new class RouteDataList()

    public class RouteDataList<T> : List<T>
    {
        public RouteDataList(IEnumerable<T> enumerable) : base(enumerable) { }
    
        public RouteDataList() : base() { }
    
        public override string ToString()
        {            
            string output = "";
            for (int i = 0; i < this.Count; i++)
            {
                output += i < this.Count - 1 ? this[i] + "-" : this[i].ToString();
            }
    
            return output;
        }
    
        public static List<Int32> ParseInts(string input)
        {
            if (String.IsNullOrEmpty(input)) return null;
    
            List<Int32> parsedList = new List<int>();
            string[] split = input.Split('-');
            foreach (string s in split)
            {
                int value;
                if(Int32.TryParse(s, out value)) parsedList.Add(value);
            }
            return parsedList;
        }
    }
    

    Use as follows:

    RouteDataList<Int32> valuelist = new RouteDataList<Int32>(){5,6,7,8};
    RouteDataList<Int32> anothervaluelist = new RouteDataList<Int32>(){12,13,14,15};
    

    Then Pass to any function that takes a RouteValueDictionary/Anonymous Type:

    return RedirectToAction("View", "Browse", new {valuelist, anothervaluelist } );
    // Produces http://www.site.com/browse/view?valuelist=5-6-7-8&anothervaluelist=12-13-14-15
    
    // To Parse back to a list:
    List<Int32> values = RouteDataList<Int32>.ParseInts(HttpContext.Current.Request.QueryString["valuelist"]) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I can tell the recommended approach for ASP.NET MVC 1 is
Is there a recommended approach for injecting Http/Request/Controller context in an ASP.NET MVC application?
What is the recommended approach to reference ASP.NET server side controls in JQuery?Currently I
There seem to be multiple means of passing model data from controllers in asp.net
I'm working on a new ASP.NET application and I'm interested in using a recommended
Dependency injection is a useful technique but what approach is recommended when faced with
What is the recommended approach building a plugin API for a ruby (rails) application?
What is the recommended approach for distributing a kernel module using a RPM? Ideally,
I have tried the recommended approach for percentage sizing of rows in LinearLayout using
When creating a desktop application in Netbeans, what is the recommended approach in separating

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.