BiosealMVCWeb.Controllers.NewsCenterController.Detail C# (CSharp) Method

Detail() public method

public Detail ( ) : System.Web.Mvc.ActionResult
return System.Web.Mvc.ActionResult
        public ActionResult Detail()
        {
            db = new biosealEntities();

            int id = Convert.ToInt32(Request.QueryString["id"]);
            var news = db.News.Where(i => i.Id == id).Single();
            int NewsTypeId = news.CategoryId;
            //获取上一条下一条记录
            var prenews = db.News.Where(i => i.Id < id && i.CategoryId ==NewsTypeId).OrderByDescending(i => i.Id).FirstOrDefault();
            ViewBag.prenews = prenews;

            var nextnews = db.News.Where(i => i.Id > id && i.CategoryId == NewsTypeId).OrderBy(i => i.Id).FirstOrDefault();
            ViewBag.nextnews = nextnews;

            return View(news);
        }