示例#1
0
        public ActionResult Create(About about, HttpPostedFileBase PostImage)
        {
            ModelState.Remove("CreatedOn");
            ModelState.Remove("ModifiedOn");
            ModelState.Remove("ModifiedName");

            if (ModelState.IsValid)
            {
                if (PostImage != null &&
                    (PostImage.ContentType == "image/jpeg" ||
                     PostImage.ContentType == "image/jpg" ||
                     PostImage.ContentType == "image/png"))
                {
                    string filename = $"about_{about.Title.Trim()}.{PostImage.ContentType.Split('/')[1]}";

                    PostImage.SaveAs(Server.MapPath($"~/images/{filename}"));
                    about.AboutImage = filename;
                }

                aboutManager.Insert(about);
                return(RedirectToAction("Index"));
            }
            BusinessLayerResult <About> res = aboutManager.InsertAboutFoto(about);

            return(View(about));
        }