I am currently trying to route in the following way.
- / routes to Home controller, view action, "home" as id
- /somePageId routes to Home controller, view action, "somePageId" as id
- /Videos routes to Videos controller, index action
- /Videos/someVideoName routes to Videos controller, video action with id param as "someVideoName"
- /News routes to News controller, index action
- /News/someNewsId routes to news controller, view action, "someNewsId" as the id.
So far, i have the following code:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "TheSportsOfficeWeb.Controllers" }
);
routes.MapRoute(
name: "NewsIndex",
url: "News",
defaults: new { controller = "News", action = "Index" },
namespaces: new[] { "TheSportsOfficeWeb.Controllers" }
);
routes.MapRoute(
name: "NewsView",
url: "News/{id}",
defaults: new { controller = "News", action = "_", id = UrlParameter.Optional },
namespaces: new[] { "TheSportsOfficeWeb.Controllers" }
);
routes.MapRoute(
name: "PageShortCut",
url: "{id}",
defaults: new { controller = "Home", action = "_", id = UrlParameter.Optional },
namespaces: new[] { "TheSportsOfficeWeb.Controllers" }
);
If i go to /Home/_/About, i can view the page, if i go to /About, i just get a 404.
Is this possible in mvc.net? If so, how would i go about this?