1

In my website, I have the following default route:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

When I access the Index page from the Home controller, I get the following address:

http://localhost/MyWebsite/

Everything is okay, however, I would like to add another default route for the following Controller and Page:

http://localhost/MyWebsite/Profile/Index/8

For the link above, I would like to have the following route:

http://localhost/MyWebsite/Profile/8

Without showing the "Index" page name.

How is it possible?

giacomelli
  • 7,287
  • 2
  • 27
  • 31
Dan
  • 1,518
  • 5
  • 20
  • 48

1 Answers1

0

Inside the RouteConfig, set enable to route Actions via Attribute:

routes.MapMvcAttributeRoutes();

After that, add the Attribute Route above the Action name:

[Route("Perfil/{id}")]
public ActionResult Index(int? id)
{
    return View();
}
Dan
  • 1,518
  • 5
  • 20
  • 48