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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:12:40+00:00 2026-05-15T04:12:40+00:00

The routing I need is quite simple, I must be missing something there. As

  • 0

The routing I need is quite simple, I must be missing something there. As code example I put the simpler situation where I can reproduce my behavior.

You have this ActionMethod :

 public ActionResult Index(string provider)
 {
     ViewData["Message"] = provider;
     return View("Index");
 }

And you have this route :

 routes.MapRoute(
      null,
      "{controller}/{action}/{provider}", 
      new { controller = "Home", action = "Index", provider = "Default" }
 ); // Parameter defaults

You can call /Home/Index/Custom and provider will take the value “Custom”

What Route would I need if I want the url /?provider=Custom to map the provider to the parameter.
I thought that would just work, because the default controller and the default action would be used, and the provider from the querystring would be used instead of the default one.
but the querystring is just ignored here.

That’s a problem in my situation as I have a form using HTTP GET method.
The form action has to be Html.BeginForm(c=>c.Index(null)) which is resolved as / and the value of my form are added in the querystring. (the provider being a dropdown in the form)

So the url built by the form is /?abc=value&cde=value…

UPDATE

The accepted answer below (see the comments) led me to this solution:

 routes.MapRoute(
     "Search",
     "search/",
     new { controller = "Home", action = "Index" }
 );

 routes.MapRoute(
    null,
    "{controller}/{action}/{provider}",
    new { controller = "Home", action = "Index", provider = "Default"} 
 );

And declare the form like so :

 Html.BeginRouteForm("Search", FormMethod.Get){
 ...
 }

This way, the form will work with the provider in the QueryString (when I use the named route search) but in all other case, I will use the default route. 🙂

  • 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-15T04:12:41+00:00Added an answer on May 15, 2026 at 4:12 am

    When I set the provider to urlparameter.optional instead of a static value, I get the behavior that you are looking for. I don’t think I can explain fully why this works whereas having a static default value set does not, but give it a try and see if it helps. If it works, you may also want to develop a custom route for your form so you can maintain your default provider in your routes as opposed to doing custom checking in your controllers.

    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{provider}", _
        New With {.controller = "Home", .action = "Index", .provider = UrlParameter.Optional} _
    )
    

    UPDATE:

    Also, you do not have to have the parameters in your route to pass them to a controller action method. For instance, using the route above, I can have this URL

    http://localhost:49705/home/about/default?otherValue=testme
    

    And this controller method

        Function About(ByVal provider As String, ByVal otherValue As String) As ActionResult
        ViewData("Message") = provider & "|" & otherValue
        Return View()
    End Function
    

    Which outputs the string default|testme

    This URL does the same as above: http://localhost:49705/home/about/?provider=default&otherValue=testme

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

Sidebar

Related Questions

I need to do some special routing in cake, but can't for the life
I need to create a custom routing for this url: /par1/par2/par3/par99/11 The url must
I have the following code using normal Zend routing and I need to convert
I need to strip a URL for routing. For that matter the parameters must
I need to have the URL like photos/13/rate => I have created following routing
I'm working on my ecommerce on kohana 3.2. i need to setup the routing
in routing.yml I can ressource other routing configs with: AcmeTestBundle: resource: @AcmeTestBundle/Resources/config/routing.xml prefix: /
My url routing is working properly inside Areas folder, that means i can go
This is my routing tables where do I put the various '.aspx' registrations? //Turns
I have successfully gotten my low-level mouse hook code to work, but there are

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.