My WebApi action method returns an IQueryable and I want to modify it (apply paging & filtering) through an ActionFilterAttribute in Asp.Net WebApi(Not MVC). The following thread I got how to access the passed model :
.Net Web API IActionFilter.OnActionExecuted return type
but how can I change/replace the whole model with something else?
I found it!
First I should cast
actionExecutedContext.ActionContext.Response.Content
intoObjectContent
(you should have a refrence toSystem.Net.Http.Formatting.dll
file in your project)after then you can simply do the following :
Note : to use
TryGetContentValue
method you need to importusing System.Net.Http;
namespace although calling this methoud is not important in the above code.:: UPDATE ::
If you need to change the Content's value type (for example returning a string instead of IQueryable) you can't simply change the value. You should create a new content like this :