So, I'm learning MVC and I've encountered a problem.
What I need to be able to do is to have a /Views/{parameter} route that redirects to a certain method(a method which loads content from the database.
It looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Views",
"Views/{id}",
new {controller = "Views", action = "Any", id = "{id}"});
//I've alternatively tried using id = UrlParameter.Optional but
//this doesn't seem to help.
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Now, this redirects any sort of a Views/{parameter} option to the method Any from the ViewsController. Here is what it looks like:
public ActionResult Any()
{
Data = new TempDataDictionary();
Data.Add("View", Request.Url.Segments.LastOrDefault());
View Complete Post