Routing with querystring parameters

Last post 04-01-2008 11:52 PM by pure.krome. 2 replies.

Sort Posts:

  • Routing with querystring parameters

    04-01-2008, 7:35 PM
    • Loading...
    • netstruc65
    • Joined on 03-10-2008, 10:13 PM
    • Posts 8

    I'm replacing an existing asp.net app, with an asp.net mvc app. The old app used a lot of querystring params, and I need to map those into controller actions, everytime I stick  ? or & into a route i get a runtime error.

     Here's what I'm trying to do.

    www.myapp.com/Products/Review.aspx?prodID=1456 should be replaced by something more RESTful, but I need to maintain backwards compatibility because of SEO, bookmarks, favorites, etc.

     I tried,

    RouteTable.Routes.Add(new Route("Product/Reviews.aspx?productID={productID}", new MvcRouteHandler())
    {
        Defaults = new RouteValueDictionary(new {controller="Reviews", action = "List"}),
    });

    The list action takes an int called productID.

     

    Filed under: , ,
  • Re: Routing with querystring parameters

    04-01-2008, 10:58 PM
    • Loading...
    • paul.vencill
    • Joined on 02-01-2006, 12:57 PM
    • Gaithersburg, MD
    • Posts 656

    You don't need to route them, they'll get passed to the controller.as-is (as params to the action if you name them such)

    e.g. . . . .Add(new Route("Product/Reviews.aspx"),new MvcRouteHandler())  do the rest as you have it.  Then in your controller,

     

    public void List(string productID){...}

     

    Paul

  • Re: Routing with querystring parameters

    04-01-2008, 11:52 PM
    • Loading...
    • pure.krome
    • Joined on 05-28-2006, 4:45 AM
    • Melbourne, Australia
    • Posts 230

    would it be best to maybe have the old url's give an HTTP 301 Moved Permanently response header thingy? this way Search Engines are updated?

    :: Never underestimate the predictability of stupidity ::
Page 1 of 1 (3 items)