public ActionResult Agregar(Foto foto, int Categorias, HttpPostedFileBase file)
        {
            Categoria categoria = db.Categorias.Find(Categorias);
            foto.Categoria = categoria;
            foto.url = "vacia";
            try
            {
                if (ModelState.IsValid)
                {
                    db.Fotos.Add(foto);
                    db.SaveChanges();

                    string path = AppDomain.CurrentDomain.BaseDirectory;
                    string filePath = path + "/Images/portafolio/" + categoria.id_categoria + ".jpg";
                    file.SaveAs(filePath);
                    foto.url = "/Images/portafolio/" + categoria.id_categoria + ".jpg";
                    db.Entry(foto).State = EntityState.Modified;
                    db.SaveChanges();

                }
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return View("Error");
            }
        }
 public ActionResult Editar(Foto foto)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(foto).State = EntityState.Modified;
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     catch (Exception ex)
     {
         TempData["Error"] = ex.Message;
         return View("Error");
     }
 }
 public ActionResult Agregar()
 {
     Foto foto = new Foto();
     ViewBag.Categorias = new SelectList(db.Categorias, "id_categoria", "nombre");
     return View(foto);
 }