I would like to add the httpcontext name property in a generic way to my objects before I save it to the database and I thought I could use the OnActionExecuting method to do that.
I'm using one of web api life cycle hooks OnActionExecuting. And I'm trying to cast the incoming parameter to List<object> but it keeps failing with the error saying it cannot complete the task:
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (context.ModelState.IsValid)
        {
            try
            {
                var result = context;
                var actionParameter = context.ActionArguments["dtoItem"];
                List<object> collection = (List<object>)actionParameter;
                    context.ActionArguments["dtoItem"] = actionParameter;
                }
            }
            catch
            {
            }
        }
    }
The error that I get for this is:
Unable to cast object of type
'System.Collections.Generic.List1[Ctrac.WebApi.Core.Models.TestModel]' to type 'System.Collections.Generic.List1[System.Object]'.
 
    