首先,我是第一次接触Kendo Uploder。我的页面上有一个kendo Uploader。我不知道我做错了什么,因为它没有命中我的VB方法。
标记:
<script id="fileTemplate" type="text/x-kendo-template">
<span class='k-progress'></span>
<div class='file-wrapper'>
<h4 class='file-heading file-name-heading'>Name: #=name#</h4>
<h4 class='file-heading file-size-heading'>Size: #=size# bytes</h4>
<button type='button' class='k-upload-action'></button>
</div>
</script>
<script>
$(document).ready(function () {
$("#files").kendoUpload({
multiple: true,
async: {
saveUrl: "NewFolder.aspx/UploadSubSRFiles",
removeUrl: "Remove",
autoUpload: true
},
upload: onUpload,
template: kendo.template($('#fileTemplate').html())
});
function onUpload(e) {
var paramsEmailDocs = "{'strFiles':'" + e.files + "'}"
Request.files
$.ajax({
type: "POST",
url: "NewFolder.aspx/UploadSubSRFiles",
data: paramsEmailDocs ,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
}
})
}
});
</script>HTML:
<div id="example" class="k-content">
<input type="file" name="files" id="files" />
</div>VB方法:
''' <summary>
''' Method for getting the Template Service request Object
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
<WebMethod()> _
Public Shared Function UploadSubSRFiles(ByVal strFiles As HttpPostedFileBase) As Boolean
Try
If lngUserID > 0 Then
Return True
Else
Return Nothing
End If
Catch ex As Exception
Debug.WriteLine("Error in UploadSubSRFiles method of Folder page: " + ex.Message)
Return Nothing
End Try
End Function问题:当我拖动文件时,在前端。文件描述根据模板来正确。但是VB方法永远不会被使用。我是个新手,所以可能是我的VB或脚本代码错了。请指点一下。
任何帮助都将受到高度的感谢。
发布于 2014-04-08 16:35:09
您不能使用$.ajax上载文件。基本上您不需要设置upload事件处理程序。只需设置async.saveUrl就足够了。这是一个现场演示的http://demos.telerik.com/kendo-ui/web/upload/async.html
发布于 2021-06-16 21:26:01
不能将参数传递给使用.aspx或.asmx方法处理文件上载的方法。您必须做的是创建一个上传处理程序。
JS代码:
$("#files").kendoUpload({
multiple: false,
async: {
saveUrl: '/UploadHandler.ashx'
},
upload: function (request) {
// custom parameters
request.data = { companyId: _companyId };
}
});C# (VB)
<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.Web;
public class UploadHandler : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
var file = context.Request.Files[0];
var companyId = context.Request.Form["companyId"];
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}如果您不需要传递自定义参数,只需从.asmx的.aspx页面web方法从Context.Request.Files获取文件即可。
https://stackoverflow.com/questions/22929471
复制相似问题