action
VodeEntities db = new NewVode.Models.VodeEntities(); int pagesize = 3; public ActionResult Index(string title, int page = 1) { var sql = "select * ,row_number() over ( order by id desc ) as rownum from vode"; if (!string.IsNullOrEmpty(title)) { sql = string.Format("{0} where title like '%{1}%'", sql, title); } var conn = db.Database.Connection; var sql2 = string.Format("select top {1} * from ({0}) as a where a.rownum>({2}-1)*{1} and a.rownum<={1}*{2}", sql, pagesize, page); var list = conn.Query(sql2); ViewBag.curPage = page; var total = conn.QueryFirst ("select count(id) from (" + sql + ") as a"); ViewBag.curPageTotal =Math.Ceiling((double)( total / pagesize)); ViewBag.stitle = title; return View(list); }
html
@model IEnumerable@{ ViewBag.Title = "Index";} Index