public ActionResult AddJunba(ForumSection forumssde, HttpPostedFileBase file) { try { var forummi = Request["post_nume"]; var userid = Convert.ToInt32(Session["User_id"]); if (file != null) { var foruimg = Request["FsectionImg"]; if (foruimg != null) { string filePath = foruimg; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"\Images\essay\") + filename; string relativepath = @"/Images/essay/" + filename; file.SaveAs(serverpath); forumssde.FsectionImg = relativepath; } else { return(Content("<script>;alert('请先上传军吧图片!');history.go(-1)</script>")); } var forubackimg = Request["FsectionbackImg"]; if (forubackimg != null) { string filePath = forubackimg; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"\Images\essay\") + filename; string relativepath = @"/Images/essay/" + filename; file.SaveAs(serverpath); forumssde.FsectionbackImg = relativepath; } else { return(Content("<script>;alert('请先军吧背景图片!');history.go(-1)</script>")); } } if (ModelState.IsValid) { forumssde.ForumSectionName = forummi; forumssde.User_id = userid; PostManage.AddForumsection(forumssde); return(Content("<script>;alert('创建成功!');window.location.href='/Forum/ClassifyPost'</script>")); } } catch (DbEntityValidationException ex) { return(Content(ex.Message)); } return(View()); }