ASP.NET MVC controllers that inherit from the Controller can easily process the requests made to actions not defined. To do this, all you have to do is override the method HandleUnknownAction() and implement the logic that we want to run in these cases.
In the following code, the requests made to /Home/Index and /Home/About will be processed normally, but /Home/ActionPage will be processed by HandleUnknownAction , whose implementation will show the view “Index” with a personalized message:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
protected override void HandleUnknownAction(string strActionName)
(
ViewData ["Message"] = "Are you trying to" + strActionName + "?"
View("Index").ExecuteResult(this.ControllerContext);
)
)
Happy Programming!!