asp.net mvc 无刷新加载
1、视图(index)
1<!--start-->2<divdata-am-widget="list_news"class="am-list-newsam-list-news-default">3<!--列表标题-->4<divclass="am-list-news-bd">5<ulclass="am-list"id="NewsList">6@{Html.RenderPartial("PartialNews",Model);}7</ul>8</div>9</div>10<buttontype="button"class="am-btnam-btn-primaryam-btn-block"pageindex="1"onclick="LoadData(this,'/News/Index?Id=@ViewBag.Id','NewsList')">加载更多</button>11<buttonclass="am-btnam-btn-default"><iclass="am-icon-spinneram-icon-spin"></i>加载中</button>12<!--end-->
2、对应的部分视图(PartialNews)
1@foreach(variteminModel)2{3<liclass="am-gam-list-item-descedam-list-item-thumbedam-list-item-thumb-left">4<divclass="am-u-sm-4am-list-thumb">56<ahref="/Mobile/News/Detail/@item.ID"class="">7<imgsrc="@(item.Image??"/Images/defaultnew.png")"alt="@item.Title"/>8</a>9</div>10<divclass="am-u-sm-8am-list-main">11<h4class="am-list-item-hd">12<ahref="/Mobile/News/Detail/@item.ID"class="text_block">@item.Title</a>13</h4>14<divclass="am-list-item-text">@item.CreateDate</div>15<divclass="am-list-item-text">@item.MinDes.RemoveHTMLTags()</div>16</div>17</li>18}
3、js函数
1<script>2functionLoadData(o,u,p){3$(o).hide().next().show();4varpageindex=parseInt($(o).attr("pageindex"));5pageindex++;6$(o).attr("pageindex",pageindex);7if(u.indexOf('?')<0){8u=u+"?from=data"9}10$.get(u+"&pageindex="+pageindex,function(data){11if(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>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。