Last active
April 19, 2016 09:48
-
-
Save pedroadaodev/a60979707ddec49ae15aa8b352bd5061 to your computer and use it in GitHub Desktop.
Create custom routes in Umbraco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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