Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 上载文件始终为空_C#_Asp.net Mvc_Model View Controller - Fatal编程技术网

C# 上载文件始终为空

C# 上载文件始终为空,c#,asp.net-mvc,model-view-controller,C#,Asp.net Mvc,Model View Controller,当我试图上传一个文件时,它总是空的,但是用户名会被忽略 <div class="container"> @using(Html.BeginForm("Upload", "ADImage", FormMethod.Post, new { enctype = "mulipart/form-data" })) { <fieldset> <legend>AD Image Upload</legend>

当我试图上传一个文件时,它总是空的,但是用户名会被忽略

<div class="container">
    @using(Html.BeginForm("Upload", "ADImage", FormMethod.Post, new { enctype = "mulipart/form-data" }))
    { 
        <fieldset>
            <legend>AD Image Upload</legend>
            <label>AD Username</label>
            <div class="input-control text" data-role="input-control">
                <input type="text" name="username" placeholder="Username" />
                <button class="btn-clear" tabindex="-1" type="button"></button>
            </div>
            <label>Choose File</label>
            <div class="input-control file info-state" data-role="input-control">
                <input type="file" name="file" tabindex="-1" style="z-index: 0;" />
                <input type="text" id="input_file_wrapper" readonly style="z-index: 1; cursor: default;" />
                <button class="btn-file" type="button"></button>
            </div>

            <button type="submit" value="Submit">Submit</button>
        </fieldset>
    }
</div>

表单的
enctype
字段中存在输入错误。是的

"mulipart/form-data"
但应该是

"multipart/form-data"

请注意缺少的“t”。

表单的
enctype
字段中有一个打字错误。是的

"mulipart/form-data"
但应该是

"multipart/form-data"

请注意缺少的“t”。

如果文件为
null
,则根据当前的检查结果,如果(file==null | file.ContentLength.Equals(0))您在
enctype
中输入错误,则应为
“多部分/表单数据”
-t为missing@Habib这在
的else
中,所以它可能没有被点击,因为
username
正在传入。但这绝对是一个很好的观点-应该是
|
而不是
|
@christoph。对于双管(
|
),您的注释是正确的,这是您在C中常见的注释。但是,这里的代码有一个管道(
|
),它仍然有效,但不会导致短路,这意味着管道的两侧都将执行。这就是为什么双管道更常见的原因。与@JoeEnos注释相关:当您打算使用逻辑运算符时,不要使用位运算符。如果文件为
null
,则根据当前的检查
if(file==null | file.ContentLength.Equals(0))应该以null引用异常结束
您在
enctype
中有一个输入错误,应该是
“多部分/表单数据”
-t是missing@Habib这是在
else
中,因此它可能不会被命中,因为
username
正在传入。但这绝对是一个很好的观点-应该是
|
而不是
|
@christoph。对于双管(
|
),您的注释是正确的,这是您在C中常见的注释。但是,这里的代码有一个管道(
|
),它仍然有效,但不会导致短路,这意味着管道的两侧都将执行。这就是为什么双管道更常见的原因。与@JoeEnos注释相关:当您打算使用逻辑运算符时,不要使用位运算符。