I have a custom collection that has its own properties.
public interface IPagedList<T>: IList<T>
{
int TotalCount { get; }
}
And I have a class that implemented an interface IPagedList
.
public class PagedList<T> : List<T>, IPagedList<T>
{
public PagedList(IQueryable<T> source){
AddRange(source);
}
public int TotalCount { get; private set; }
}
When I used the class PagedList<T>
in my web api application, the property is TotalCount
not serialized.
public class EmpolyeeController : ApiController
{
public IHttpActionResult Get()
{
IPagedList<Employee> response = new PagedList<Employee>(Database.GetEmplyees());
return Ok(response);
}
}
The answer is:
[
{
"Id": "1230a373-af54-4960-951e-143e75313b25",
"Name": "Deric"
}
]
But I want to see the TotalCount property in the json response.

Property in Raw View, as you can see in screencast.
(I think these are Raw View IList serialization problems json.net. How to add Raw View middleware)
source
share