I'm trying to create a simple site. Basically it has one Controller Home
controller.
This controller has an action Index
takes a string
as argument (which is a directory) and uses that 'directory' to do its work.
I can't work out how to create a generic catch all route that will send every URL to this one Action.
Any URL combination could exist, and anything beyond the domain name should be the string.
http://<domain>/2008
http://<domain>/2008/09
http://<domain>/2008/09/Fred
Does anyone know how to do this? It would also be alright if all the values are passed as a list.
Is there a better way of doing this?
Try this :
routes.MapRoute(
"Default", "{*path}",
new { controller = "Home", action = "Index" }
);
And the controller :
public class HomeController : Controller {
public ActionResult Index(string path) {
return View();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With