コード例 #1
0
ファイル: NewsController.cs プロジェクト: shroshri/churchweb
        public ActionResult Create(Newstable newstable, HttpPostedFileBase file)
        {
            if (ModelState.IsValid && file != null && file.ContentLength > 0)
            {
                churchdbEntities1 db = new churchdbEntities1();
                string ImageName = System.IO.Path.GetFileName(file.FileName);
                string physicalPath = Server.MapPath("~/nimage/" + ImageName);

                // save image in folder
                file.SaveAs(physicalPath);

                Newstable newRecord = new Newstable();

                newRecord.Nhead= Request.Form["Nhead"];
                newRecord.Ndate = Request.Form["Ndate"];
                newRecord.Ntext = Request.Form["Ntext"];
                newRecord.NUrl = "~/nimage/" + ImageName;
                db.Newstables.Add(newRecord);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(newstable);
        }
コード例 #2
0
ファイル: NewsController.cs プロジェクト: shroshri/churchweb
 /*---------------------------------------------------------*/
 public ActionResult Nlisting(int page = 1)
 {
     churchdbEntities1 db = new churchdbEntities1();
     return View(db.Newstables.OrderByDescending(v => v.Nid).ToPagedList(page, 3));
 }