SHARE
TWEET

How do I set a “Default Action” for my Controller that will be called when no other action matches

a guest Feb 28th, 2012 17 Never
  1. routes.MapRoute("Default", "{controller}/{action}/{id}",
  2.     new { controller = "Home", action = "Index", id = "" });
  3.        
  4. protected override void HandleUnknownAction(string actionName) {
  5.   //your code here.
  6. }
  7.        
  8. routes.MapRoute("default-action", "{controller}/{actionName}/{id}", new {action="DefaultAction"});
  9.        
  10. public ActionResult DefaultAction(string actionName, string id) {
  11.   //handle default action
  12. }
RAW Paste Data
Top