C#
public ActionResult BiaoDan(int? page) { int pageindex = 1; if (page > 0) { pageindex = (int)page; } var pagesize = 6; pageindex = pageindex - 1; var db = new ddrDBEntities(); var rowcount = db.BiaoDan.Count(); if (rowcount < 1) { return Content("暂时没有客户的留言信息<br /><a href='/admin/admin'>返回</a>"); } if (page < 1) { return Redirect("/admin/biaodan/?page=1"); } var pagecount = rowcount / pagesize; if(rowcount % pagesize >0) { pagecount +=1; } if (pageindex+1 > pagecount) { return Redirect( string.Format("/admin/biaodan/?page={0}",pagecount)); } var objs = db.BiaoDan .OrderByDescending(m=>m.ShiJian) .Skip<BiaoDan>(pageindex*pagesize) .Take(pagesize) .ToList(); db.Dispose(); return View(objs); } public JsonResult DelBiaoDan() { var objid = Guid.Parse(Request["delid"]); using (var db = new ddrDBEntities()) { var obj = db.BiaoDan.Where(m => m.Id == objid).FirstOrDefault(); db.BiaoDan.DeleteObject(obj); db.SaveChanges(); } var result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; result.Data = new { flag = true }; return result; } }
CSHTML
@model IEnumerable<ddr.Models.BiaoDan> @{ ViewBag.Title = "德迪尔电器有限公司-后台管理-客户留言信息"; Layout = "~/Views/Shared/_AdminLayout.cshtml"; int Page; try { Page = Convert.ToInt32(Request["page"]); } catch { Page = 1; } } <script> function del(id) { $.getJSON("/admin/delbiaodan/?delid=" + id, function (data) { if (data["flag"] == true) { alert("删除成功"); window.location.href = window.location.href; } }) } </script> <hr style="width: 400px; margin-right: auto; margin-left: auto;" /> @foreach (var obj in Model) { <div style="width: 400px; margin-right: auto; margin-left: auto; text-align: left;"> <font color="red">时间:</font>@obj.ShiJian <br /> <font color="red">内容:</font>@Html.Raw(obj.NeiRong) <br /> <a href="javascript:del('@obj.Id');" style="color:Red">删除此信息</a> <hr /> </div> } <a href="/admin/biaodan/?page=@(Page - 1)" style="color:Red">上一页</a> <a href="/admin/biaodan/?page=@(Page + 1)" style="color:Red"> 下一页</a> <a href="/admin/biaodan/" style="color: Red">首页</a> <a href="/admin/biaodan/?page=@int.MaxValue" style="color:Red"> 末页</a>
时间: 2024-09-27 04:55:29