Search code examples
asp.net-mvc-3urlmaproute

Ugly url in mvc3-how make it nice looking?


Have an action in Ideas controller in my aplication:

public ViewResult NewIdeas(int numberOfPage = 1)

that action "produces" url like that:

/Ideas/NewIdeas/?numberOfPage=1

it's quite ugly-it should be just:

/Ideas/NewIdeas/1

I know that new MapRoute propably will solve problem-but how it should look like? Thanks for help.


Solution

  • You should add a new route in global.asax:

      routes.MapRoute(
          "NewIdeas", // Route name
          "Ideas/NewIdeas/{numberOfPage}", // URL with parameters
          new { controller = "Ideas", action = "NewIdeas", numberOfPage= UrlParameter.Optional } // Parameter defaults
      );