我正在使用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>和我的控制器
[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();
}
}如果(文件== null )(在这行(
file)在上传png图像后显示null)
这个代码有什么问题?
发布于 2017-05-23 06:58:14
检查表单属性
人们犯的一个常见错误是表单标签中缺少以下部分:
<form enctype="multipart/form-data">
</form>同样,在MVC中,您的表单结构可能类似于
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "myForm", @role="form" }))https://stackoverflow.com/questions/44127682
复制相似问题