public ActionResult Edit([Bind(Include = "ID,title,author,date,content,subCategoryID,ClickTimes,filename,filetype")] InformationContent informationContent) { string file = Request.Form["MyUploadile"]; string filename = Request.Form["name"]; int max_id = db.InformationContent.Max(d => d.ID); ViewBag.ID = max_id + 1; ViewBag.subCategoryID = new SelectList(db.InformationSubCategory, "ID", "Name", informationContent.subCategoryID); if (ModelState.IsValid)//文件上传 { var files = Request.Files; if (files.Count > 0) { var file1 = files[0]; string strFileSavePath = Request.MapPath("~/files");//文件存储路径 file1.SaveAs(strFileSavePath + "/" + filename); } informationContent.filename = filename; informationContent.filetype = "." + filename.Split('.').Last(); db.Entry(informationContent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(informationContent)); }
// GET: OfficeInformation/Delete/5 //public ActionResult Delete(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // InformationContent informationContent = db.InformationContent.Find(id); // if (informationContent == null) // { // return HttpNotFound(); // } // return View(informationContent); //} //// POST: OfficeInformation/Delete/5 //[HttpPost, ActionName("Delete")] //[ValidateAntiForgeryToken] public ActionResult Delete(int id, InformationContent informationContent1) { InformationContent informationContent = db.InformationContent.Find(id); db.InformationContent.Remove(informationContent); db.SaveChanges(); return(Content("<script>alert('已成功删除!');window.location.href='/OfficeInformation/Index'</script>")); }
public ActionResult chakan(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InformationContent informationContent = db.InformationContent.Find(id); ViewBag.name = informationContent.filename; if (informationContent == null) { return(HttpNotFound()); } ViewBag.subCategoryID = new SelectList(db.InformationSubCategory, "ID", "Name", informationContent.subCategoryID); return(View(informationContent)); }
public ActionResult Create([Bind(Include = "ID,title,author,date,content,subCategoryID,ClickTimes,filename,filetype")] InformationContent informationContent) { string file = Request.Form["MyUploadile"]; string filename = Request.Form["name"]; int max_id = 0; ViewBag.ID = max_id; var model = from a in db.InformationContent orderby a.ID descending select a; if (model.Count() != 0) { ViewBag.ID = model.First().ID + 1; } ViewBag.subCategoryID = new SelectList(db.InformationSubCategory, "ID", "Name", informationContent.subCategoryID); if (ModelState.IsValid)//文件上传 { if (filename != "") { var files = Request.Files; if (files.Count > 0) { var file1 = files[0]; string strFileSavePath = Request.MapPath("~/files/OfficeInformation");//文件存储路径 file1.SaveAs(strFileSavePath + "/" + filename); } } informationContent.filename = filename; informationContent.filetype = "." + filename.Split('.').Last(); informationContent.ClickTimes = 0; db.InformationContent.Add(informationContent); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(informationContent)); }