简体   繁体   中英

Route config trims all the params in the get request

I have a route config in MVC project:

routes.MapRoute(
                name: "Client",
                url: "Client/{webUi}/{lang}/{*controllerUrl}",
                defaults: new
                {
                    controller = "Client",
                    action = "Index",
                    lang = "en-GB"
                }
            );

I have a ClientController with method Index().

public ActionResult Index(string webUi, string lang, string controllerUrl)
        { ... }

I am trying to use URL:

Client/ZWS/{lang}/ImportBundles?from=bundle

However, when I am debugging the ClientController, I am getting that the value in controllerUrl is ImportBundles. The parameters from=bundle is just stripped away.

Is it possible to achieve?

Thanks in advance!

Edit:

  1. I just tried to use this URL:

    Client/ZWS/{lang}/ImportBundles/from/bundle

And it worked. But is it possible to use this format:

Client/ZWS/{lang}/ImportBundles?from=bundle

Not exactly, but you can access everything after the ? inside your Action by accessing Request.QueryString .

Request.QueryString["from"] //would evaulate to "bundle"

You don't need the * for the catch-all in route definition to do that. If your format will always be Client/ZWS/{lang}/ImportBundles?from=bundle , you can get rid of it at the end of your route definition

...
url: "Client/{webUi}/{lang}/{controllerUrl}",

and controllerUrl will still evaluate to "ImportBundles"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM