Search code examples
asp.net-mvc-2request.querystring

Request.QueryString in MVC


In my HomeController I'm trying to get information using Request.QueryString

        string aa = Request.QueryString["aa"];
        string bb = Request.QueryString["bb"];

So In the address bar I am expecting something like:

< something >?aa=12345&bb=67890

I created a new route:

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

And I'm trying to use it in this way:
http://localhost:54321/Receive?aa=12345&bb=67890

But I'm getting the following error:

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Receive


Solution

  • I think your routing is goofed which is why you are getting a 404. Please look at some tutorials, specifically here: asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs

    Also, like @YuriyFaktorovich says, you really shouldn't be using Request.QueryString, but rather passing those as parameters to your action method

    Example in VB:

    Function Retrieve(ByVal aa as String, ByVal bb as String) as ActionResult