Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Create([Bind(Include = "ProdutoId,Nome,Descricao,Valor,CategoriaId,imagem")] Produto produto, int? id, HttpPostedFileBase file)
- {
- if (ModelState.IsValid)
- {
- if (file != null)
- {
- string pic = System.IO.Path.GetFileName(file.FileName);
- string path = System.IO.Path.Combine(
- Server.MapPath("~/Imagens/"), pic);
- // file is uploaded
- file.SaveAs(path);
- produto.imagem = pic.ToString();
- // save the image path path to the database or you can send image
- // directly to database
- // in-case if you want to store byte[] ie. for DB
- using (MemoryStream ms = new MemoryStream())
- {
- //Aqui converter para Base64 caso queira salvar a imagem toda no banco
- file.InputStream.CopyTo(ms);
- byte[] array = ms.GetBuffer();
- //Faça o atributo ImagemArray receber a string convertida
- //img.ImagemArray
- }
- }
- ProdutosDAO.Add(produto);
- return RedirectToAction("Index");
- }
- ViewBag.CategoriaId = new SelectList(Singleton.Instance.Entities.Categorias, "CategoriaId", "CategoriaNome", produto.CategoriaId);
- return View(produto);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement