コード例 #1
0
        // POST: ManageProduct/Create
        //[HttpPost]
        public ActionResult Create(Product product, HttpPostedFileBase file)
        {
            //tring path = Server.MapPath("~/Products/" + file.FileName);
            string ImageName    = System.IO.Path.GetFileName(file.FileName);
            string physicalPath = Server.MapPath("~/Products/" + ImageName);

            product.Image = ImageName;

            // save image in folder
            file.SaveAs(physicalPath);

            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    db.Products.Add(product);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                PopulateTypeIdDropDownList(product.TypeId);
                return(View(product));
            }
            catch
            {
                return(View());
            }
        }
コード例 #2
0
 public ActionResult Create(Product product)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             db.Products.Add(product);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         PopulateTypeIdDropDownList(product.TypeId);
         PopulateImageUrlDropDownList(product.Image);
         return(View(product));
     }
     catch
     {
         return(View());
     }
 }