Alex
Alex

Reputation: 36161

ASP.NET MVC: How to get Request.QueryString value when routing

Let's say I have the following rule

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

And in the controller

public ActionResult Forums(int id)
    {
        Response.Write(id); // works
        Response.Write(Request.QueryString["id"]); // doesn't

        return View();
    }

How can I get it with Request.QueryString?

Upvotes: 1

Views: 10874

Answers (1)

Ola Herrdahl
Ola Herrdahl

Reputation: 4296

I think you need to go through RouteData to access the routing parameters.

E.g.

Routedata.Values["id"]

Upvotes: 6

Related Questions