.NET Framework Class Library
Controller..::.HandleUnknownAction Method

Called when a request matches this controller, but no method with the specified action name is found in the controller.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)
Syntax

Visual Basic (Declaration)
Protected Overridable Sub HandleUnknownAction ( _
    actionName As String _
)
Visual Basic (Usage)
Dim actionName As String

Me.HandleUnknownAction(actionName)
C#
protected virtual void HandleUnknownAction(
    string actionName
)
Visual C++
protected:
virtual void HandleUnknownAction(
    String^ actionName
)

Parameters

actionName
Type: System..::.String
The name of the attempted action.
Remarks

The result object that is prepared by this method is written to the response by the MVC framework when the object is executed.

Examples

The following example shows how to render views that do not have a matching ActionResult method. For example, if you have a Details.aspx view but no corresponding method exists that returns an ActionResult instance, the following example displays the Details view when a request to for the Details action is made on the controller. If there is no matching view, the error page displays a message. This example shows one way to use the [M:System.Web.Mvc.Controller.HandleUnknownAction(System.String) method.] Action methods are not required to return an ActionResult object.

C#
protected override void HandleUnknownAction(string actionName) {
    try {
        this.View(actionName).ExecuteResult(this.ControllerContext);
    } catch (InvalidOperationException ieox ) {
        ViewData["error"] = "Unknown Action: \"" + 
            Server.HtmlEncode(actionName) + "\"";
        ViewData["exMessage"] = ieox.Message;
        this.View("Error").ExecuteResult(this.ControllerContext);
    }
}  
Visual Basic
Protected Overloads Overrides Sub HandleUnknownAction(ByVal actionName As String) 
    Try 
        Me.View(actionName).ExecuteResult(Me.ControllerContext) 
    Catch ieox As InvalidOperationException 
        ViewData("error") = "Unknown Action: """ & Server.HtmlEncode(actionName) & """" 
        ViewData("exMessage") = ieox.Message 
        Me.View("Error").ExecuteResult(Me.ControllerContext) 
    End Try 
End Sub
See Also

Reference

Tags :


Page view tracker