Skip to content

Instantly share code, notes, and snippets.

@pedroadaodev
Last active April 19, 2016 09:48
Show Gist options
  • Save pedroadaodev/a60979707ddec49ae15aa8b352bd5061 to your computer and use it in GitHub Desktop.
Save pedroadaodev/a60979707ddec49ae15aa8b352bd5061 to your computer and use it in GitHub Desktop.
Create custom routes in Umbraco
public class CustomRoutes
{
public static void Register()
{
RouteTable.Routes.MapRoute(
name: "Product",
url: "Product/{action}/{id}", // dont use {controller}
defaults: new {
controller = "Product", // dont skip this line
action = "Index",
id = UrlParameter.Optional
}
);
}
}
// ADD THIS IN THE GLOBAL.CS FILE
// IF THE FILE IS NOT AVAILABLE CREATE ONE
public class Global : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// ADD THIS LINE TO REGISTER THE NEW CUSTOM ROUTES
CustomRoutes.Register();
}
}
public class ProductController : Controller
{
public ActionResult Index(string id)
{
// create a view under /Views/Product/Index.cshtml
return View();
}
public ActionResult Comments(string id)
{
// create a view under /Views/Product/Comments.cshtml
return View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment