2014-02-06 54 views
0

我在使用MVC的kendo控件。我有一個基本的上傳工作,但我需要動態創建它們並在後端處理該代碼。這是我認爲的工作Kendo MVC多個上傳器

<input name="attachments" type="file" id="attachments" /> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#attachments").kendoUpload({ 
      async: { 
       saveUrl: '@Url.Action("Save", "AppConfig")', 
       autoUpload: true 
      } 
     }); 
}); 
</script> 
[HttpPost] 
    public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments) 
    { 

     if (SaveUploadedFile(attachments, "Background")) 
     { 
      return Content(""); 
     } 
     else 
     { 
      return Content("error"); 
     } 

    } 

不過,我需要做的是動態創建的ID和處理它在後臺簡單的例子。所以,這就是我正在做的文件上傳

@foreach (var item in Model) { 
    string fid = String.Format("{0}{1}", @item.fieldType, @item.appConfigId.ToString()); 
       <input name="@fid" id="@fid" type="file" /> 
       <script type="text/javascript"> 
        $(document).ready(function() { 
         $("#@fid").kendoUpload({ 
         async: { 
          saveUrl: '@Url.Action("Save", "AppConfig")', 
          autoUpload: true 
         } 
        }); 
       }); 
       </script> 

} 

現在,我得到了HttpPostedFileBase參數必須符合您的HTML元素的ID,但我不知道如何修改背後的代碼,讓我可以採取多個上傳。有任何想法嗎?

回答

0

爲什麼不直接使用上傳器的功能multiple?它是默認啓用的。

+0

因爲我現在的情況不會允許的。每個文件上傳屬於特定的。我只是淡化了我的代碼在這裏閱讀它的人的用途。這個for循環要複雜得多。 –