Reputation: 24093
I use ScriptServices to return IPaged<> result:
[WebService]
public IPaged<int> DoSomething() {
....
....
}
IPaged<> is:
public interface IPaged<T> : IEnumerable where T : class
{
int PageNumber { get; }
int PageSize { get; }
IEnumerable<T> Items { get; }
int PagesCount { get; }
int TotalItemsCount { get; }
}
The Paged<> class that returned from DoSomething implements IPaged<> and therefore implements the IEnumerator GetEnumerator()
:
public IEnumerator GetEnumerator()
{
return ((IEnumerable)Items).GetEnumerator();
}
Whenever I call DoSomething from Javascript ajax, the script service engine returns IEnumerable instance and not IPaged so I get an array (the Items member from GetEnumerator() method).
How can I return IPaged<> and not IEnumerable<> from the script service?
Upvotes: 2
Views: 261
Reputation: 1063694
A bit of a guess, but it is very common for IEnumerable[<T>]
(and also sometimes IList[<T>]
to take priority over anything else, and jump into the "colllection of" branch (ignoring any properties defined on the "container").
As such, I expect your best bet is to not have IPaged<T>
implement IEnumerable<T>
.
This may mean having to change a few places to add .Items
.
Another approach would to add a ForJson()
extension method that returns something similar to IPaged<T>
, but without implementing IEnumerable[<T>]
.
Upvotes: 1