Search code examples
javascripthtmljqueryasp.net-mvc-3-areas

how to find current request is ajax or not in mvc3 view javascript


i have div with max height and overflow - auto, when div size overflows scroll bar added automatically, but i set

$("#itemsdiv").scrollTop(10000); 

so that scroll bar is always at bottom . Now i want that if view is load with ajax request then scrollbar is at bottom , and if view load when page refreshing then scroll bar will at top of div. can any one help me

thank you


Solution

  • @if(Request.IsAjaxRequest())
     {
         <script>        
        //If Ajax Request Code Here
       $("#itemsdiv").scrollTop(10000);
       </script>
     }
     else
     {
        <script>//Else here
        $("#itemsdiv").scrollTop(10);
       </script>
     }
    

    Put the Above code in your View