Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="form-group">
- @Html.LabelFor(model => model.Foto, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- <input type="file" name="ImageData" id="ImageData" />
- </div>
- </div>
- [HttpPost]
- public ActionResult MakaleOlustur(Makale m, HttpPostedFileBase file)
- {
- try
- {
- using (MvcBlogContext context = new MvcBlogContext())
- {
- Makale _makale = new Makale();
- if (file != null && file.ContentLength > 0)
- {
- MemoryStream memoryStream = file.InputStream as MemoryStream;
- if (memoryStream == null)
- {
- memoryStream = new MemoryStream();
- file.InputStream.CopyTo(memoryStream);
- }
- _makale.Foto = memoryStream.ToArray();
- }
- _makale.Baslik = m.Baslik;
- _makale.OlusturmaTarihi = DateTime.Now;
- _makale.Icerik = m.Icerik;
- context.Makale.Add(_makale);
- context.SaveChanges();
- return RedirectToAction("Makale", "Admin");
- }
- }
- catch (Exception ex)
- {
- throw new Exception("Eklerken hata oluştu" + ex.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement