• context.Request.Files为NULL问题


    在实现图片上传功能的时候出现在ashx等处理页面出现context.Request.Files为NULL异常,有几点需要注意:

    1、在客户端可以将form用submit提交,如下:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="JS/jquery-1.3.2.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript">
            function UpLoad() {
                $("#form1").submit();           
            }
           
        </script>

    </head>
    <body>
        <form id="form1" method="post" enctype="multipart/form-data" action="ImageHandler.ashx">
        <div>
            <input id="File1" type="file" runat="server"/>
            <input id="Button1" type="button" value="上传" onclick="UpLoad()" /></div>
            <div id="imgList"></div>     
        </form>
    </body>
    </html>

    2、form表单需要加上属性method="post" enctype="multipart/form-data"

    3、文件控件需要加上runat="server"属性

  • 相关阅读:
    字符串练习题
    算法题
    readLine()
    grep家族
    java_IO
    集合框架
    常用类
    异常
    Mysql 图形工具 Navicat
    Mysql内置功能《一》流程控制
  • 原文地址:https://www.cnblogs.com/tianguook/p/2084139.html
Copyright © 2020-2023  润新知