public ActionResult AddImage(string data) { Models.Images newImage = new Images(); newImage.IMAGE_URL = Request["IMAGE_URL"]; newImage.IMAGE_ALT = Request["IMAGE_ALT"]; db.Images.Add(newImage); db.SaveChanges(); /* var objects = JArray.Parse(data); // parse as array * foreach (JObject root in objects) * { * foreach (KeyValuePair<String, JToken> app in root) * { * var imageId = app.Key; * var imageUrl = (String)app.Value["IMAGE_URL"]; * var imageAlt = (String)app.Value["IMAGE_ALT"]; * * } * }*/ return(Json("Başarılı:")); }
public ActionResult Add(Image imageModel) { string fileName = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName); string extension = Path.GetExtension(imageModel.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; imageModel.ImagePath = "~/Image/" + fileName; fileName = Path.Combine(Server.MapPath("~/Image/"), fileName); imageModel.ImageFile.SaveAs(fileName); int userID = (int)Session["userID"]; imageModel.User_ID = userID; using (ImagesEntities db = new ImagesEntities()) { db.Images.Add(imageModel); db.SaveChanges(); } ModelState.Clear(); ViewBag.SuccessMessage = "Uploaded successful"; return(View("Add", new Image())); }