public ActionResult Cria(string nome, int id, HttpPostedFileBase file) { try { SalaDAO salaDao = new SalaDAO(); Sala sala = new Sala() { Nome = nome, CodProfessor = id }; if (file != null) { byte[] imageBytes = new byte[file.InputStream.Length + 1]; file.InputStream.Read(imageBytes, 0, imageBytes.Length); sala.Img = imageBytes; } salaDao.Adiciona(sala); return(Redirect("/Home/Sala/" + sala.Id)); } catch (Exception e) { Session["msg"] = "Erro: " + e.Message; return(Redirect(Request.UrlReferrer.ToString())); } }