// GET: /File/Create public ActionResult Add(int? Id) { File model = new File() { FileCategory = db.FileCategories.Find(Id) }; return View(model); }
public ActionResult Add(File file, HttpPostedFileBase fileData) { if (ModelState.IsValid) { string filePath = Server.MapPath("~/Files/" + DateTime.Now.ToString("dd.MM.yyyy hh-mm-ss") + fileData.FileName); fileData.SaveAs(filePath); file.Path = filePath; file.FileCategory = db.FileCategories.Find(file.FileCategory.Id); db.Files.Add(file); db.SaveChanges(); return RedirectToAction("Details", "Category", new { id = file.FileCategory.Id }); } ViewBag.FileCategories = db.FileCategories; return View(file); }