asp.net mvc-5 HttpPostedFileBase 为空
asp.net mvc-5 HttpPostedFileBase is null
我正在使用 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();
}
}
if (file == null)(on this line (file
) is showing me null after i am uploading png image)
这段代码有什么问题?
检查表单属性
人们常犯的一个错误是在表单标记中遗漏了以下部分:
<form enctype="multipart/form-data">
</form>
同样在 MVC 中,您的表单结构可能看起来像这样
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "myForm", @role="form" }))
我正在使用 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();
}
}
if (file == null)(on this line (
file
) is showing me null after i am uploading png image)
这段代码有什么问题?
检查表单属性
人们常犯的一个错误是在表单标记中遗漏了以下部分:
<form enctype="multipart/form-data">
</form>
同样在 MVC 中,您的表单结构可能看起来像这样
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "myForm", @role="form" }))