Exemplo n.º 1
0
        public ActionResult CreateSave(AuthorModel a)
        {
            AuthorFactory factory = new AuthorFactory();

            a.a_id    = factory.自動產生a_id();
            a.a_Birth = Request.Form["a_Birth"];

            int point = a.image.FileName.LastIndexOf(".");
            //副檔名
            string extention = a.image.FileName.Substring(point, a.image.FileName.Length - point);
            //這一行會幫我們在上傳到資料庫的時候 重新命名,例如 FB 的檔名那樣,16進制的編碼
            string photoName = Guid.NewGuid().ToString() + extention;

            //把 SaveAs 變成相對路徑的方法
            a.image.SaveAs(Server.MapPath("../作者照片/" + photoName));
            a.a_Image = "../作者照片/" + photoName;

            factory.Create(a);

            return(RedirectToAction("Create"));
        }