From 9aaec5fe2e75811eb21f330883f08b8e052e418a Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Thu, 29 Jun 2017 20:50:52 +0100 Subject: [PATCH] Move Action filter example to correct section The Action filters sample was previously at the end of the Exceptions filter section. Moved it to the end of the Action filters section instead. --- aspnetcore/mvc/controllers/filters.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aspnetcore/mvc/controllers/filters.md b/aspnetcore/mvc/controllers/filters.md index b547907154..ba6a6c7ab9 100644 --- a/aspnetcore/mvc/controllers/filters.md +++ b/aspnetcore/mvc/controllers/filters.md @@ -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.