Merge pull request #3602 from andrewlock/patch-4

Move Action filter example to correct section
pull/3605/head
Scott Addie 2017-06-29 16:33:20 -05:00 committed by GitHub
commit 6fc0456276
1 changed files with 6 additions and 6 deletions

View File

@ -255,6 +255,12 @@ For an `IAsyncActionFilter`, a call to the `ActionExecutionDelegate` executes an
The framework provides an abstract `ActionFilterAttribute` that you can subclass.
You can use an action filter to automatically validate model state and return any errors if the state is invalid:
[!code-csharp[Main](./filters/sample/src/FiltersSample/Filters/ValidateModelAttribute.cs)]
The `OnActionExecuted` method runs after the action method and can see and manipulate the results of the action through the `ActionExecutedContext.Result` property. `ActionExecutedContext.Canceled` will be set to true if the action execution was short-circuited by another filter. `ActionExecutedContext.Exception` will be set to a non-null value if the action or a subsequent action filter threw an exception. Setting `ActionExecutedContext.Exception` to null effectively 'handles' an exception, and `ActionExectedContext.Result` will then be executed as if it were returned from the action method normally.
## Exception filters
*Exception filters* implement either the `IExceptionFilter` or `IAsyncExceptionFilter` interface. They can be used to implement common error handling policies for an app.
@ -276,12 +282,6 @@ Exception filters are good for trapping exceptions that occur within MVC actions
The framework provides an abstract `ExceptionFilterAttribute` that you can subclass.
You can use an action filter to automatically validate model state and return any errors if the state is invalid:
[!code-csharp[Main](./filters/sample/src/FiltersSample/Filters/ValidateModelAttribute.cs)]
The `OnActionExecuted` method runs after the action method and can see and manipulate the results of the action through the `ActionExecutedContext.Result` property. `ActionExecutedContext.Canceled` will be set to true if the action execution was short-circuited by another filter. `ActionExecutedContext.Exception` will be set to a non-null value if the action or a subsequent action filter threw an exception. Setting `ActionExecutedContext.Exception` to null effectively 'handles' an exception, and `ActionExectedContext.Result` will then be executed as if it were returned from the action method normally.
## Result filters
*Result filters* implement either the `IResultFilter` or `IAsyncResultFilter` interface, and their execution surrounds the execution of action results.