简体   繁体   English

如何在mvc3视图中查找当前请求是否为ajax

[英]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 我的div具有最大高度和溢出-自动,当div大小溢出时,滚动条会自动添加,但是我设置了

$("#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. 现在我想如果用ajax请求加载视图,则滚动条在底部,如果刷新页面时加载视图,则滚动条将在div顶部。 can any one help me 谁能帮我

thank you 谢谢

@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 将上面的代码放入您的视图中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM