【问题标题】:Sending Metadata when Upload is async in Kendo Upload - Metedata is Null在 Kendo Upload 中上传异步时发送元数据 - 元数据为 Null
【发布时间】:2021-07-14 19:47:26
【问题描述】:

我正在使用 Kendo 进行异步上传。我正在传递如下元数据:

https://docs.telerik.com/kendo-ui/controls/editors/upload/metadata

<body>
<div id="example">
    <div>
        <div class="demo-section k-content">
            <div id="FldUpload" style="width:100%;height:40%;">
                <b>Matter ID : </b><span id="spanMatterName"></span><br />
                <div><input name="files" id="folders" type="file" multiple /></div>
            </div>                
        </div>
    </div>



$("#folders").kendoUpload({
  async: {
       saveUrl: baseAddrs + "/" + "DragAndDrop/ChunkSave",
       removeUrl: baseAddrs + "/" + "DragAndDrop/remove",
       chunkSize: 10530000, //~ 10MB
       autoUpload: true,
       concurrent: true
     },
         upload: onUpload,
         directory: true,
         directoryDrop: true,
});

function onUpload(e) {
    e.data = {
        EntityID: document.getElementById("spanMatterName").textContent
    };
    alert(e.data.EntityID); // It has correct value
}

//Codebehind
 [HttpPost]
 public ActionResult ChunkSave(IEnumerable<HttpPostedFileBase> files, string metaData)
 {
    //Here metadata is always null
 }

为什么元数据为空?我如何将 (e.data) 的元数据值传递给代码隐藏 POST 方法?

【问题讨论】:

  • 根据文档:If set, e.formData replaces the payload of the upload request. 您能否设置一个调试器或使用console.log 来检查e.formData 是否为空?

标签: javascript c# kendo-ui kendo-asp.net-mvc


【解决方案1】:

我修好了。参数名称应该与您在 e.data 中传递的名称完全相同,在我的情况下它是 EntityID 但我在 post 方法中将变量声明为字符串元数据:

 e.data = {
        EntityID: document.getElementById("spanMatterName").textContent
    };

It should be 
[HttpPost]
 public ActionResult ChunkSave(IEnumerable<HttpPostedFileBase> files, string EntityID)
 {
    
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2015-11-03
    相关资源
    最近更新 更多