Объект Jqgrid загрузить изображение не передает данные в базу
This is a last attempt for me to get some insight on this issue before I scratch JqGrid all together. I have a col in my colModel to upload an Image. I am using ajaxfileupload. Although there are several of the same examples out there they seem to work for others but mine is not. When I select an Image from the enctype: "multipart/form-data" for some reason it is not putting anything in the record for the object. I have a few breakpoints and when I view the data everything is visible but the product Image. So all fields are there and ProductImage is null. It is like JqGrid is not holding the object and passing it. Since it is null, nothing gets uploaded either. Maybe I am missing something but I have looked through my code over and over again and it appears to be just like what I have read in examples that supposedly work.
Любая помощь была бы фантастической, так как я готов поцарапать это и использовать что-то еще.
Ниже приведен мой код для этого процесса. только секции. если вам нужно увидеть другой код, дайте мне знать.
Что я уже пробовал:
JqGrid:
{ name: "ProductImage", index: "ProductImage", mtype: "Post", editable: true, editrules: { required: true }, edittype: "file", search: true, resizable: false, width: 210, align: "left", editoptions: { enctype: "multipart/form-data" } }, ..... { // edit option zIndex: 100, url: "/Admin/EditProducts", closeOnEscape: true, closeAfterEdit: true, recreateForm: true, afterSubmit: uploadImage, afterComplete: function (response) { if (response.responseText) { alert(response.responseText); } } }, .... function uploadImage(response, postdata) { //debugger; //var json = $.parseJSON(response.responseText); //if (json) return [json.success, json.message, json.id]; //return [false, "Failed to get result from server.", null]; var data = $.parseJSON(response.responseText); if (data.success == true) { if ($("#ProductImage").val() != "") { ajaxFileUpload(data.id); } } return [data.success, data.message, data.id]; } function ajaxFileUpload(id) { $.ajaxFileUpload( { url: "/Admin/UploadImage", secureuri: false, fileElementId: "ProductImage", dataType: "json", data: { id: id }, success: function (data, status) { if (typeof (data.isUploaded) != "undefined") { if (data.isUploaded == true) { return; } else { alert(data.message); } } else { return alert("Failed to upload image!"); } }, error: function (data, status, e) { return alert("Failed to upload image!"); } } ) return false; }
Контроллер:
public string EditProducts(Product product) { string msg; try { if (ModelState.IsValid) { using (StoreEntities db = new StoreEntities()) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); msg = "Saved Successfully"; } } else { msg = "Did not save! "; } } catch (DbEntityValidationException ex) //catch (Exception ex) { msg = "Error occured:" + ex.Message; foreach (var validationErrors in ex.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Diagnostics.Debug.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return msg; } .... #region Upload Images [HttpPost] public JsonResult UploadImage(HttpPostedFileBase ProductImage) { string directory = "~/Images/"; if (ProductImage != null && ProductImage.ContentLength > 0) { var fileName = Path.GetFileName(ProductImage.FileName); ProductImage.SaveAs(Server.MapPath(Path.Combine(directory, fileName))); //ProductImage.SaveAs(Path.Combine(directory, fileName)); } return Json(new { isUploaded = true, message = "Uploaded Successfully" }, "text/html"); } #endregion
Gerry Schmitz
Может быть, если бы вы объяснили, "что" вы хотите сделать.
Использование "сетки" для "загрузки изображений" - понятие, чуждое многим.
Имена файлов, ногти на пальцах, ссылки, которые мы получаем.
Member 13812021
I am using jqgrid to show my records. Since it has the capability of adding and editing also I thought it was the clean way to go. Ultimately I would like to add a record with a image link included with the product. The link would be where the file Upload creates the folder and image storage preferably the category that it is in. So create a folder inside of the images folder (if not there already) and put the photo in it. I believe that I can handle the thumbnail with just Css when the page is loaded. But if you think, for display purposes it would be better to load a thumbnail instead than I would probably have to agree that it would make load time quicker. Also not looking for inline editing either. The popup provided is good enough.
Member 13812021
Я получил файл для загрузки, но все еще не могу сохранить имя файла в базе данных, которую он загружает. Поэтому когда я загружаю изображение я бы хотел чтобы запись сохраняла имя файла в столбце ProductImage