Skip to content

Instantly share code, notes, and snippets.

@JeffryGonzalez
Created August 31, 2011 15:01
Show Gist options
  • Save JeffryGonzalez/1183760 to your computer and use it in GitHub Desktop.
Save JeffryGonzalez/1183760 to your computer and use it in GitHub Desktop.
Restful Routes MVC3
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Destroy",
"{controller}/{id}",
new { action = "Destroy" },
new { id=@"\d+", httpMethod = new RestHttpMethodConstraint("DELETE") }
);
routes.MapRoute(
"Update",
"{controller}/{id}",
new { action = "Update" },
new { id=@"\d+", httpMethod = new RestHttpMethodConstraint("PUT") });
routes.MapRoute(
"Create",
"{controller}",
new { action = "Create" },
new { httpMethod = new RestHttpMethodConstraint("POST") });
routes.MapRoute(
"Delete",
"{controller}/Delete/{id}",
new { action = "Delete" },
new { httpMethod=new RestHttpMethodConstraint("GET"), id=@"\d+" }
);
routes.MapRoute(
"Edit",
"{controller}/Edit/{id}",
new { action = "Edit" },
new { httpMethod = new RestHttpMethodConstraint("GET"), id = @"\d+" });
routes.MapRoute(
"New",
"{controller}/New",
new { action = "New" },
new { httpMethod = new RestHttpMethodConstraint("GET") });
routes.MapRoute(
"Show",
"{controller}/{id}",
new { action = "Show" },
new { httpMethod = new RestHttpMethodConstraint("GET"), id = @"\d+" });
routes.MapRoute(
"Index",
"{controller}",
new { action = "Index" },
new { httpMethod = new RestHttpMethodConstraint("GET") }
);
//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
//);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment