예제 #1
0
        public ActionResult Index(Mother mother, string childname, HttpPostedFileBase file)
        {
            var child = new Child();
            child.ChildName = childname;

            if (file!= null)
            {
                child.fileName = file.FileName;
                child.file = file;
                //child.fileStream = file.InputStream;
            }

            mother.Childs.Add(child);

            return View(mother);
        }
        public ActionResult Index(Mother m, HttpPostedFileBase file_nomodel, string childname)
        {
            // Init model
            var mother = new Mother();

            // Get saved Model from previous, As File type can only save in Session, and lost if communicated with view and Controller
            if (TempData["mother"] != null)
            {
                mother = TempData["mother"] as Mother;
            }

            if (Request.Files.Count > 0)
            {
                for (int i = 0; i < Request.Files.Count; i++ )
                {
                    var child = new Child();
                    child.ChildName = childname;
                    child.fileName = Request.Files[i].FileName;
                    child.file = Request.Files[i];
                    mother.Childs.Add(child);
                }
            }

            //if (file_nomodel != null)
            //{
            //    var child = new Child();
            //    child.ChildName = childname;
            //    child.fileName = file_nomodel.FileName;
            //    child.file = file_nomodel;
            //    mother.Childs.Add(child);
            //}
            mother.MotherName = m.MotherName;
            TempData["mother"] = mother;

            return View(mother);
        }