Click here to Skip to main content
14,550,550 members
Rate this:
Please Sign up or sign in to vote.
Guys I tried get datas from database by scroll mouse event but it doesnt work. I shared my code. My "pageno" always get "0". I dont know thats why. All codes works but like I said "pageno" always "0" and no data is coming.

public IActionResult Index(int? pageno)
       {
           int pageSize = 10;
           List<TweetDTO> tweets = null;
           if (pageno == null)
           {
               tweets = _tweetService.GetTweets().OrderBy(X=>X.Id).Take(pageSize).ToList();
           }
           else
           {
               tweets = _tweetService.GetTweets().OrderBy(X=>X.Id).Skip(pageSize * pageno.Value).Take(pageSize).ToList();
           }
           bool isAjax = HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
           if (isAjax)
           {
               return PartialView("~/Member/Views/Shared/_TweetShowPartial.cshtml", tweets);
           }
           return View(tweets);

       }

<script type="text/javascript">
    var PageNumber = 0;
        var PagePost = true;

        $(window).scroll(function () {
        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
            if (SayfaPost) {
                $.ajax({
                    url: '/Member/Home/Index',
                    data: { "pageno": PageNumber },
                    success: function (data) {
                        if ($.trim(data) == '') {
                          
                            PagePost = false;
                        
                        } else {
                            $("#TweetList").append(data);
                            PageNumber++;
                        }
                    }
                });
            }
        }
    });

<div>Tweet List</div>
<div id="TweetList">
    @await Html.PartialAsync("_TweetShowPartial",Model)
</div>


What I have tried:

.............................................
Posted
Updated 22-May-20 10:28am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100