首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kendo Uploader不工作

Kendo Uploader不工作
EN

Stack Overflow用户
提问于 2014-04-08 14:42:15
回答 2查看 5K关注 0票数 0

首先,我是第一次接触Kendo Uploder。我的页面上有一个kendo Uploader。我不知道我做错了什么,因为它没有命中我的VB方法。

标记:

代码语言:javascript
复制
    <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:

代码语言:javascript
复制
<div id="example" class="k-content">
     <input type="file" name="files" id="files" />
</div>

VB方法:

代码语言:javascript
复制
    ''' <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或脚本代码错了。请指点一下。

任何帮助都将受到高度的感谢。

EN

回答 2

Stack Overflow用户

发布于 2014-04-08 16:35:09

您不能使用$.ajax上载文件。基本上您不需要设置upload事件处理程序。只需设置async.saveUrl就足够了。这是一个现场演示的http://demos.telerik.com/kendo-ui/web/upload/async.html

票数 0
EN

Stack Overflow用户

发布于 2021-06-16 21:26:01

不能将参数传递给使用.aspx或.asmx方法处理文件上载的方法。您必须做的是创建一个上传处理程序。

JS代码:

代码语言:javascript
复制
  $("#files").kendoUpload({
            multiple: false,
            async: {
                saveUrl: '/UploadHandler.ashx'
            },
            upload: function (request) {
                // custom parameters
                request.data = { companyId: _companyId };
            }
        });

C# (VB)

代码语言:javascript
复制
<%@ 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获取文件即可。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22929471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档