コード例 #1
0
        public ActionResult Create(HttpPostedFileBase file, CollectionViewModel c, FormCollection collection)
        {
            //Get the selected values ID from the category dropdown list
            int id = Convert.ToInt32(collection["listbox"]);

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("/Content/Img"),
                                               Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    ViewBag.Message  = "File uploaded successfully";
                    c.Movie.Image    = "~/Content/Img/" + file.FileName;
                    c.Movie.Category = new MovieReference.Category()
                    {
                        ID = id
                    };
                    c.Movie.User = new MovieReference.UserTable {
                        ID = userId
                    };
                    movieObj.AddMovie(c.Movie);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    //ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    Response.Write("ERROR:" + ex.Message);
                }
            }
            else
            {
                //ViewBag.Message = "You have not specified a file.";
                Response.Write("You have not specified a file.");
            }
            return(null);
        }