Scroll Infinity ASP NET MVC C#

Asked

Viewed 138 times

5

Good afternoon, I am implementing an infinite list in Asp net mvc and I have some questions 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 well. But I also saw that it is possible to do this by returning a JSON with the data and assembling it via javascript and displaying to the user, what would be the best way? JSON or partial view?

  • It’s the "same" thing only instead of making a request per page, returning the rendered html to be displayed, you would do the same thing with a Json and let Javascript build this html. Or you make a single request to bring all the content of that page to JSON and only control the view

  • Partialview is already ready to do the append, if you receive the json return should be faster and lighter, but you will have to generate all html in javascript, you decide :)

  • So the two forms are correct, maybe with json get a little faster, beauty was just what I wanted to know, I’m a little engaged with performance and good practices

  • Even if it comes as json, you’ll still get the processing to assemble the html and give it expensive append. The difference is that if you bring all the JSON at once, you will get an unnecessary load of information that may never be displayed. If you use a partialview and give append, it will be faster, because if you look at the implementation of the engine of Razor, you will see that it is well done mounting html. : ) Everything has a cost, whether processing (client or server) or network (transfer more data). Be engaged with performance, but not so much if it’s not a critical issue.

  • that’s how I’m doing, I load every 30 items and every time I need to fetch more, I’ll pick up the current position and look in the bank from that position

1 answer

1


Rafael, make paginated query in the database, if you are using Sql Server, from version 2012 the model 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 inform the amount of Rows you want to display, e.g.: instead of @0 you inform from which record you want to search, and instead of @1 you inform even when you want to search, in the case of showing from 30 on 30 record would be: @0=0 and @1=30, then in the second request, @0=31 and @1=60, and so on. The "total" variable in the query will contain the total number of records located. This helps you a lot in performance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.