温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

asp.net mvc 无刷新加载

发布时间:2020-07-29 14:23:17 来源:网络 阅读:320 作者:胡壮壮 栏目:编程语言

    

1、视图(index)

asp.net mvc 无刷新加载

 1     <!--start--> 2     <div data-am-widget="list_news" class="am-list-news am-list-news-default"> 3         <!--列表标题--> 4         <div class="am-list-news-bd"> 5             <ul class="am-list" id="NewsList"> 6                 @{ Html.RenderPartial("PartialNews", Model);} 7             </ul> 8         </div> 9     </div>10     <button type="button" class="am-btn am-btn-primary am-btn-block" pageindex="1" onclick="LoadData(this,'/News/Index?Id=@ViewBag.Id', 'NewsList')">加载更多</button>11     <button class="am-btn am-btn-default" ><i class="am-icon-spinner am-icon-spin"></i>加载中</button>12     <!--end-->

asp.net mvc 无刷新加载

2、对应的部分视图(PartialNews)

asp.net mvc 无刷新加载

 1 @foreach (var item in Model) 2 { 3     <li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left"> 4         <div class="am-u-sm-4 am-list-thumb"> 5              6             <a href="/Mobile/News/Detail/@item.ID" class=""> 7                 <img src="@(item.Image??"/Images/defaultnew.png")" alt="@item.Title" /> 8             </a> 9         </div>10         <div class=" am-u-sm-8 am-list-main">11             <h4 class="am-list-item-hd">12                 <a href="/Mobile/News/Detail/@item.ID" class="text_block">@item.Title</a>13             </h4>14             <div class="am-list-item-text">@item.CreateDate</div>15             <div class="am-list-item-text">@item.MinDes.RemoveHTMLTags()</div>16         </div>17     </li>18 }

asp.net mvc 无刷新加载

3、js函数

asp.net mvc 无刷新加载

 1 <script> 2         function LoadData(o, u, p) { 3             $(o).hide().next().show(); 4             var pageindex = parseInt($(o).attr("pageindex")); 5             pageindex++; 6             $(o).attr("pageindex", pageindex); 7             if (u.indexOf('?') < 0) { 8                 u = u + "?from=data" 9             }10             $.get(u + "&pageindex=" + pageindex, function (data) {11                 if (data == "") {12                     $(o).attr("pageindex", parseInt($(o).attr("pageindex")) - 1)13                     $(o).show().next().hide()14                     $(o).html("没有更多了!");15                     $(o).removeAttr("onclick");16                 } else {17                     $(data).appendTo($("#" + p));18                     $(o).show().next().hide()19                 }20             });21         }22     </script>

asp.net mvc 无刷新加载


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI