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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:55:36+00:00 2026-05-20T07:55:36+00:00

I want my searches like those in Stack Overflow (i.e. no action, no slashes):

  • 0

I want my searches like those in Stack Overflow (i.e. no action, no slashes):

mydomain.com/search                        --> goes to a general search page  
mydomain.com/search?type=1&q=search+text   --> goes to actual search results  

My routes:

routes.MapRoute(  
  "SearchResults",  
  "Search/{*searchType}",      --> what goes here???  
  new { action = "Results" }  
);  
routes.MapRoute(  
  "SearchIndex",  
  "Search",  
  new { action = "Index" }  
);  

My SearchController has these actions:

public ActionResult Index() { ... }  
public ActionResult Results(int searchType, string searchText) { ... }  

The search results route does not work. I don’t want to use the “…/…” approach that everyone seems to be using, because a search query is not a resource, so I want the data in a query string as I’ve indicated, without slashes–exactly like SO does.

TIA!Matt

  • 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-20T07:55:37+00:00Added an answer on May 20, 2026 at 7:55 am

    You don’t need two routes because you’re providing search parameters as query string. Just have one search route:

    routes.MapRoute(
        "Search",
        "Search",
        new { controller = "Search", action = "Search" }
    );
    

    Then write this controller action

    public ActionResult Search(int? type, string q)
    {
        var defaultType = type.HasValue ? type.Value : 1;
        if (string.IsNullOrEmpty(q))
        {
            // perform search
        }
        // do other stuff
    }
    

    The body of this method greatly depends on the search condition whether you require both parameters when you search for stuff or just q and you have some default for type. Remember that page indexing can be done just the same way.

    Using strong type parameters (validation wise)

    You could of course create a class that could be validated, but property names should reflect that of the query string. So you’d either have a class:

    public class SearchTerms
    {
        public int? type { get; set; }
        public string q { get; set; }
    }
    

    And use the same request with equally named query variables as you do now, or have a clean class and adjust your request:

    public class SearchTerms
    {
        public int? Type { get; set; }
        public string Query { get; set; }
    }
    
    http://domain.com/Search?Type=1&Query=search+text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When someone searches my website using a quick search feature I would like to
I want to have a function which searches for a key in a collection
I've searched their site. I just want to find the page number in the
I'm trying to create a custom search but getting stuck. What I want is
What are the fastest search technologies apart from Relational DB Searches ? I have
I want to turn a Salesforce VisualForce Page into a widget for my corporate
So I have this website that has a search feature which searches a table
If I want to include directories to be searched for header files, which is
I searched and tried a lot, but I can't accomplish it as I want..
OK I have looked and searched all i want to do is fire a

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.