Infinite Scroll ASP NET MVC C #

5

Good afternoon, I'm implementing an infinite list in asp net mvc and I have some doubts about what is the best way to do this. I implemented using partial view, making a request via ajax and return this partial view and give an append to my html and it works fine. But I also saw that it is possible to do this by returning a JSON with the data and putting it via javascript and displaying it to the user, what would be the best way? JSON or partial view?

    
asked by anonymous 11.09.2018 / 20:24

1 answer

0

Rafael, make paged query in the database, if you are using Sql Server, from the 2012 version the template is this:

 select count(1) over() as total,column1,column2 from mytbale
where 1=1 
group by column1,column2
order by column1 offset @0 rows fetch next @1 rows only;

Each time you make a new request, you can pass two parameters to indicate the number of rows you want to display, eg: in place of @ 0 you inform from which record you want to search, and in place of @ 1 you enter until when you want to fetch, in the case of displaying every 30 records would be: @ 0 = 0 and @ 1 = 30, then on the second requisition, @ 0 = 31 and @ 1 = 60, and so on against. The "total" variable in the query will contain the total amount of records found. This helps you a lot in performance.

    
20.10.2018 / 03:13