2014-02-11 3 views
1

Я пытаюсь реализовать сетку Kendo UI с загрузкой кендо внутри сетки. В то время как я использую ASP.NET MVC, я не использую обертки Weberik MVC. Я пытаюсь сделать это без них.Kendo UI Загрузить внутри Grid

Проблема, с которой я столкнулась, заключается в том, что IEnumerable HttpPostedFileBase имеет значение null, когда возвращается к моему методу Action.

JavaScript:

$(document).ready(function() { 

     var dsGalleryItemFile = new kendo.data.DataSource({ 
      transport: { 
       read: "@Url.Content("~/Intranet/GalleryItemFile/ListFiles/")@Model.galleryItemID", 
       update: { 
        url: "@Url.Content("~/Intranet/GalleryItemFile/UpdateFile")", 
        type: "POST" 
       }, 
       destroy: { 
        url: "@Url.Content("~/Intranet/GalleryItemFile/DeleteFile")", 
        type: "POST" 
       }, 
       create: { 
        url: "@Url.Content("~/Intranet/GalleryItemFile/CreateFile/")@Model.galleryItemID", 
        type: "POST" 
       } 
      }, 
      // determines if changes will be send to the server individually or as batch 
      batch: false, 
      schema: { 
       model: { 
        id: "fileID", 
        fields: { 
         fileID: { 
          editable: false, 
          nullable: true 
         }, 
         filename: {}, 
         fileType: { defaultValue: {fileTypeID: 1, fileType: "Web JPEG"} }, 
         fileType: {}, 
         width: { type: "number" }, 
         height: { type: "number" }, 
         } 
        } 
       } 
     }); 

     $("#gvGalleryItemFile").kendoGrid({ 
      columns: [{ 
       field: "filename", 
       title: "Filename" 
      }, { 
       field: "filepath", 
       title: "File Upload", 
       editor: fileUploadEditor//, 
       //template: "<img src='#=filepath.filepath#' />" 
      }, { 
       field: "fileType", 
       title: "File Type", 
       editor: fileTypeDropDownEditor, 
       template: "#=fileType.fileType#", 

      }, { 
       field: "width", 
       title: "Width" 
      }, { 
       field: "height", 
       title: "Height" 
      }, { 
       command: ["edit", "destroy"] 
      }], 
      editable: { mode: "inline" }, 
      toolbar: ["create"], 
      dataSource: dsGalleryItemFile 
     }); 


    }); 

    function fileTypeDropDownEditor(container, options) { 
     $('<input required data-text-field="fileType" data-value-field="fileTypeID" data-bind="value:' + options.field + '"/>') 
      .appendTo(container) 
      .kendoDropDownList({ 
       autoBind: false, 
       dataSource: { 
        transport: { 
         read: "@Url.Content("~/Intranet/FileType/ListFileTypes")" 
        } 
       } 
      }); 
    } 

    function fileUploadEditor(container, options) { 
     $('<input type="file" name="fileUpload" id="fileUpload" />') 
      .appendTo(container) 
      .kendoUpload({ 
       async: { 
        saveUrl: "@Url.Content("~/Intranet/GalleryItemFile/UploadFile")" 
       }, 
       complete: onUploadComplete 
      }); 
    } 

MVC Действие:

[HttpPost] 
    public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> uploadedFiles) 
    { 
     if (uploadedFiles != null) 
     { 
      foreach (var thisFile in uploadedFiles) 
      { 
       string newFileName = Path.GetFileName(thisFile.FileName).Replace(" ", ""); 
       var physicalPath = Path.Combine(Server.MapPath("~/Areas/Gallery/Content/GalleryImages"), newFileName); 
       thisFile.SaveAs(physicalPath); 

      } 
      return Content(""); 
     } 
     else 
     { 
      return Content("Error"); 
     } 

    } 

ответ

3

Попытка назвать параметр аргумента в методе действия подписи точно так же, как имя атрибута входа, что вы превращаетесь в виджете загрузки ,

В вашем случае

public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> fileUpload) 
+0

Совершенная, еще немного новичок в MVC и кэндо. Спасибо за помощь. – Lrayh

+0

Не думайте, что вы знаете, как вернуть имя файла сценарию, чтобы сохранить его при редактировании строки? – Lrayh

+0

Вы можете отправить JSON обратно клиенту в ответ на сервер. Внутри JSON вы можете добавить это имя файла, json будет доступен внутри события обратного вызова успеха. http://docs.telerik.com/kendo-ui/api/web/upload#events-success –