I have a filter like so:
public class Err : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext context)
{
var result = context.Result;
}
}
result is an object of Microsoft.AspNetCore.Mvc.BadRequestObjectResult. It contains a StatusCode and a Value, but when I try to extract them like so: context.Result.Value, I get this error:
Error CS1061 'IActionResult' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'IActionResult' could be found.
That is simple - property Result of ActionExecutedContext has IActionResult type which doesn't have property Value. You can cast it to BadRequestObjectResult to get access to Value property:
public class Err : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext context)
{
var result = context.Result as BadRequestObjectResult;
// you can access result.Value here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With