Reputation: 45
I am trying to get value of the parameter from action method, instead of underlined value, should not there be key?(x.key) in order to get the argument name?
var param = context.ActionArguments
.SingleOrDefault(x => x.Value.ToString().Contains("DTO")).Value;
[HttpPost]
[ServiceFilter(typeof(ValidationFilterAttribute))]
public async Task<IActionResult> CreateCompany([FromBody] CompanyForCreationDTO company)
Upvotes: 2
Views: 90
Reputation: 22419
Please try this way, It will bring the parameter value of a controller which has been passed.
public void OnActionExecuting(ActionExecutingContext context)
{
var descriptor = context.ActionDescriptor as ControllerActionDescriptor;
if (descriptor != null)
{
var parameters = descriptor.MethodInfo.GetParameters();
foreach (var parameter in parameters)
{
var argument = context.ActionArguments[parameter.Name];
}
}
}
Output:
You can get more info in official document here
Upvotes: 1