FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 2567|回复: 1
打印 上一主题 下一主题

文件上传,AspNet 后面怎么写?

[复制链接]
跳转到指定楼层
楼主
发表于 2012-11-2 03:16:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

这里是前台的js,从网上找的.
var win = new Ext.Window({        title: '文件上传',        width: 400,        height: 100,        minWidth: 300,        minHeight: 100,        layout: 'fit',        plain: true,        bodyStyle: 'padding:5px;',        buttonAlign: 'center',        items: form,        buttons: [{            text: '上传',            handler: function () {                if (form.form.isValid()) {                    if (Ext.getCmp('userfile').getValue() == '') {                        Ext.Msg.alert('错误', '请选择你要上传的文件');                        return;                    }                    Ext.MessageBox.show({                        title: '请等待',                        msg: '文件正在上传...',                        progressText: '',                        width: 300,                        progress: true,                        closable: false,                        animEl: 'loding'                    });                    form.getForm().submit({                        url: 'Action/UpdateLoad',                        method: 'POST',                        success: function (form, action) {                            Ext.Msg.alert('Message',            action.result.success);                            win.close();                        },                        failure: function () {                            Ext.Msg.alert('Error',            'File upload failure.');                        }                    })                }            }        }, {            text: '关闭',            handler: function () {                win.close();            }        }]    });    win.show();

需要后台post 到接受服务,这个怎么写?


我用的Ext.Net1.5 ,里面GridPanel 不支持 uploadfield 用ajax 方法直接响应 cell command. 但接收不会.

有人能解答下么?

沙发
 楼主| 发表于 2012-11-3 01:40:00 | 只看该作者
已经解决
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Ext.Net;

namespace erp_asp_net.WebPage.Sales
{

    public class result
    {
        public bool success;
        public string msg;
    }
    /// <summary>
    /// FileResponse 的摘要说明
    /// </summary>
    public class FileResponse : IHttpHandler
    {

        // extjs submit()
        //would process the following server response for a successful submission:

        //{
        //    "success":true, // note this is Boolean, not string
        //    "msg":"Consignment updated"
        //}

        //and the following server response for a failed submission:

        //{
        //    "success":false, // note this is Boolean, not string
        //    "msg":"You do not have permission to perform this operation"
        //}
        public void ProcessRequest(HttpContext context)
        {
            result res = new result();
            context.Response.ContentType = "text/html";
            if (context.Request.Files.Count > 0)
            {
                res.success = true;
                res.msg = "成功上传";
                string respone = JSON.Serialize(res);
                string fn = context.Request.Files[0].FileName;
                //int fl = context.Request.Files[0].ContentLength;
                string strPath = context.Server.MapPath("~/") + fn;

                context.Request.Files[0].SaveAs(strPath);
                //StreamReader file = new StreamReader(context.Request.Files[0].InputStream);
                context.Response.Write(respone);
            }
            else
            {
                res.success = false;
                res.msg = "失败";
                string respone = JSON.Serialize(res);
                context.Response.Write(respone);
            }
            
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-9-29 20:14 , Processed in 0.044284 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表