user348173
user348173

Reputation: 9278

rewrite routes for URl

I have the following URl:

http://localhost:12981/BaseEvent/EventOverview/12?type=Film

This is route:

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

I want that in a browser the url looks like:

http://localhost:12981/Film/Overview/12

How can I do this?

One more example:

http://localhost:12981/BaseEvent/EventOverview/15?type=Sport

should be

http://localhost:12981/Sport/Overview/15

Thanks.

Upvotes: 0

Views: 124

Answers (1)

Iridio
Iridio

Reputation: 9271

This should work:

routes.MapRoute("", "{type}/Overview/{id}", new { controller = "Events", action = "Overview");

Then you have a controller named EventsController with an action like this one

public ViewResult Overview(string type, int id)
{
   //Your code

   return View(model);
}

Upvotes: 1

Related Questions