加载部分视图
$("#result").load("/home/message",function(){
//加载完之后隐藏进度条
});
public ActionResult message(){
return PartialView("视图",实体);
}
分页控件的使用
页面:
< div id = " CommentList " >
@ { Html . RenderAction ( " Index " , " Comment " , new { id = @ Model . ProductID , page = 1 } ) ; }
< / div >
局部视图
@ using Webdiyer . WebControls . Mvc ; @ model PagedList < Extshop . Models . T_Comment > @ { foreach ( var c in Model ) { < div class = " row " > < div class = " title " > @ c . Title < / div > < b > @ c . Username < / b > & nbsp ; 发表于 @ ( c . CreateTime ) < br / > @ c . Description < / div > } } < br / > < div class = ‘ pagenav ‘ > @ Ajax . Pager ( Model , new PagerOptions { PageIndexParameterName = " page " } , new AjaxOptions { UpdateTargetId = " CommentList " } ) < / div > Ajax分页的方法,这样,就可以使用Ajax自动更新该部分。在AjaxOption中定义了UpdateTargetId参数为“CommentList”,意味着当Ajax加载数据后,会自动更新id为“CommentList”的html元素内的内容
或
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", ShowPageIndexBox = true, FirstPageText = "首页", PrevPageText = "上一页", NextPageText = "下一页", LastPageText = "末页", PageIndexBoxType = PageIndexBoxType.TextBox, PageIndexBoxWrapperFormatString = "请输入页数{0}", GoButtonText = "转到" })
后台:
新建一个名称为“CommentController”的控制器,并修改index操作代码如下: public ActionResult Index ( int id , int ? page ) { ViewData [ " ProdcutID " ] = id ; PagedList < T_Comment > q = dc . T_Comment . Where ( m = > m . ProductID = = id ) . OrderByDescending ( m = > m . CreateTime ) . ToPagedList ( page ? ? 1 , 2 ) ; return PartialView ( q ) ; } 代码中第1个参数id表示的是产品的id,第2个参数是评论的当前页。和产品列表一样,使用mvcPager进行分页。
时间: 2024-10-19 10:14:03