不能上传图片(HttpPostedFileBase为空) [英] Cannot Upload Image (HttpPostedFileBase is Null)
本文介绍了不能上传图片(HttpPostedFileBase为空)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个图片上传但是当我点击浏览并选择图像,然后提交我的形式HttpPostedFileBase为空。是否与我的执行缺失?请帮助。
I tried to have an images uploader but when I click the browse and select image then submit my form the HttpPostedFileBase is null. Is there missing with my implementation? Please help.
查看
<form action="Home/UploadImage" method="POST">
<p>
<input type="file" accept="image/x-png, image/gif, image/jpeg" name="projectBgImage" id="projectBgImage"/>
</p>
<input type="submit" value="submit"/>
</form>
主控制器
public ActionResult UploadImage(HttpPostedFileBase projectBgImage)
{
return View();
}
调试图片
推荐答案
添加 enctype属性
你的格式
元素
<form action="Home/UploadImage" method="POST" enctype="multipart/form-data">
我建议你使用 BeginForm
HTML的帮助是这样的:
I suggest you to use BeginForm
html-helper like this:
@using (Html.BeginForm("UploadImage", "Home", FormMethod.Post, new { id = "form", enctype="multipart/form-data" }))
{
<p>
<input type="file" accept="image/x-png, image/gif, image/jpeg" name="projectBgImage" id="projectBgImage"/>
</p>
<input type="submit" value="submit"/>
}
和操作方法[HttpPost]
注释
[HttpPost]
public ActionResult UploadImage(HttpPostedFileBase projectBgImage)
{
return View();
}
额外的信息:一个漂亮的博客文章由菲尔哈克 Asp.net MVC上传
这篇关于不能上传图片(HttpPostedFileBase为空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文