I have a basic ASP.NET MVC5 app with a Restaurant class as my model and I am currently using the default out of the box routing.
/Restaurant/Create
/Restaurant/Details
/Restaurant/Index
Previously this was only based on one city. Now I would like to make this multi city and route it in such a way
London/Restaurant/Index
Manchester/Restaurant/Index
Birmingham/Restaurant/Index
I've been reading up on custom routing in ASP.NET, attribute routing, routing constraints but I cannot figure out how to achieve the above.
I tried changing the default route in RouteConfig.cs to the following but this does not work.
routes.MapRoute(
name: "Default",
url: "{city}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Here is my Restaurant Controller Index signature
public ActionResult Index(int? RestaurantId)
{
ViewBag.Restaurants = new SelectList(db.Restaurants.ToList().OrderBy(r => r.RestaurantName), "RestaurantID", "RestaurantName");
return View(db.Restaurants.ToList());
}