asp.net mvc-5 HttpPostedFileBase为空

0 asp.net-mvc file-upload httppostedfilebase asp.net-mvc-5

我正在使用asp.net mvc-5上载文件,HttpPostedFileBase但我在选择图像后却显示HttpPostedFileBase为空

这是我的代码

 <input type="file" title="search image" file-model="profileimage" id="allfilepath" name="file" />
 <button type="submit" class="btn btn-primary col-sm-5">
         <span class="glyphicon glyphicon-plus"></span>
 </button>
Run Code Online (Sandbox Code Playgroud)

和我的控制器

    [HttpPost]
    public ActionResult insert(HttpPostedFileBase file, quotationcompany quotecomp)
    {
        var allowedExtensions = new[] {
        ".Jpg", ".png", ".jpg", "jpeg"
    };
        if (file == null)
        {
            ViewBag.message = "Please Select Image";
            return View();
        }
        else {
            ViewBag.message = "Image Uploaded Successfully";
            return View();
        }

    }
Run Code Online (Sandbox Code Playgroud)

如果(文件== null)(在此行(file)在我上载png图片后显示为null)

这段代码有什么问题?

Ter*_*e00 6

检查表单属性

人们常犯的一个常见错误是在表单标签中缺少以下部分:

<form enctype="multipart/form-data">
</form>
Run Code Online (Sandbox Code Playgroud)

同样在MVC中,您的表单结构可能看起来像这样

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "myForm", @role="form" }))
Run Code Online (Sandbox Code Playgroud)