c# - Modify Microsoft Docs PaginatedList to work with standard List (.Net Core MVC) -


i have been trying follow pagination example microsoft docs

i have managed far enough when method passes paginatedlist view. in return statement complaining argument:

enter image description here

public async task<iactionresult> triptable(int? page) {     var trips = t in _tripcontext.tripmetadata select t;      page = 1;      int pagesize = 10;      return partialview("partialtripsview", await paginatedlist<tripmetadata>.createasync(trips.asnotracking(), page ?? 1, pagesize)); } 

i have managed make method work other models, reason doesn't work tripmetadata , don't know why is..

tripmetadata.cs

namespace mspfrontend.models {     public partial class tripmetadata     {         public tripmetadata()         {             tripgpsdata = new hashset<tripgpsdata>();             tripstate = new hashset<tripstate>();         }          [key]         public int tripid { get; set; }          [display(name = "start timestamp")]         public long? starttimestamp { get; set; }          [display(name = "end timestamp")]         public long? endtimestamp { get; set; }          public long? duration { get; set; }          [display(name = "average speed")]         public decimal? avgspeed { get; set; }          public decimal? distance { get; set; }          public virtual icollection<tripgpsdata> tripgpsdata { get; set; }         public virtual icollection<tripstate> tripstate { get; set; }     } } 

how can make work tripmetadata model?

update

i have tried modifying paginatedlist class adding following (non async function), without success:

public static task<paginatedlist<t>> create(list<t> source, int pageindex, int pagesize) {     var count = source.count();     var items = source.skip((pageindex - 1) * pagesize).take(pagesize).tolist();     return new paginatedlist<t>(items, count, pageindex, pagesize); } 

however complains cannot:

cannot implicitly convert type 'mspfrontend.data.paginatedlist<t>' 'system.threading.tasks.task<mspfrontend.data.paginatedlist<t>>' 

i didn't see code before update, appear mixing async , sync actions. try following code in paginatedlist, , keep rest of example code same.

changes note: (1) async now. (2) return type should iqueryable<t>

public class paginatedlist<t> : list<t> {     // ... cutting out irrelevant code     public static async task<paginatedlist<t>> createasync(iqueryable<t> source, int pageindex, int pagesize) {         var count = await source.countasync();         var items = await source.skip((pageindex - 1) * pagesize).take(pagesize).tolistasync();         return new paginatedlist<t>(items, count, pageindex, pagesize);     } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -