コード例 #1
0
        public ActionResult ToEdit(SYSAdv model)
        {
            SYSAdv OldModel  = SYSAdv.GetEntityByID(model.ID);
            string oldImgUrl = OldModel.ImgUrl;//原来的图片
            string msg       = "";

            var file = Request.Files[0];

            if (file.ContentLength > 0 && file != null)
            {
                if (file.ContentLength > 5242880)
                {
                    msg = "上传图片不能超过5MB!";
                    TempData["ToEditSYSNavAdv_Msg"] = msg;
                    return(View("Edit", model));
                }
                if (!Directory.Exists(Server.MapPath("~/images/SYSAdv/")))
                {
                    Directory.CreateDirectory(Server.MapPath("~/images/SYSAdv/"));
                }
                string path = Request.MapPath("~/");
                string ext  = Path.GetExtension(file.FileName); //获得文件扩展名
                OldModel.ImgUrl = "/images/SYSAdv/Adv_" + OldModel.ID + ext;
                string saveName = OldModel.ImgUrl;              //实际保存文件名

                string delFile = Server.MapPath("~") + oldImgUrl;
                System.IO.File.Delete(delFile);

                file.SaveAs(path + saveName);
            }
            OldModel.AdvType = 1;
            OldModel.Name    = "首页";
            OldModel.Url     = model.Url;
            OldModel.Sort    = model.Sort;
            if (OldModel.UpdateByID() > 0)
            {
                TempData["ToEditGoodsType_Msg"] = "ok";
            }
            else
            {
                TempData["ToEditGoodsType_Msg"] = "修改网站导航图片失败!";
            }
            return(View("Edit", model));
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            SYSAdv model = SYSAdv.GetEntityByID(id);

            return(View(model));
        }