In this article, I will explore Handling Unknown Actions. A Controller.HandleUnknownAction Method gets called when a controller cannot find an action method that matches a browser request. I will implement the following method in my previous article Implementing HTTP File Upload with ASP.NET MVC.
protected virtual void HandleUnknownAction(string actionName)
Here is my FileUploadController class as shown below.
public class FileUploadController : Controller
public ActionResult FileUpload()
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
if (uploadFile.ContentLength > 0)
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(uploadFile.FileName));
protected override void HandleUnknownAction(string actionName)
actionName = "FileUpload";
The above example displays the FileUpload view when a request to for the FileUpload action is made on the controller. If there is no matching view, then the FileUpload controller HandleUnknownAction() method is invoked. I have hard coded the FileUpload view so that if browser request does not match to FileUpload it will explicitly call FileUpload action. Here is the view with unknown action.
Notice that the controller does not have UploadToGoogle action, but our HandleUnknownAction() method is invoked and it explicitly calls FileUpload action.
In this article, you learned how to handle Unknown Actions in ASP.NET MVC.