【发布时间】:2017-09-25 10:28:24
【问题描述】:
看,伙计们。我正在尝试上传一些信息,但无法加载文件。只需检查代码: 查看:
<form method="post" data-toggle="validator" role="form">
<div class="not-that-right">
<div class="form-group">
<label for="Photo">Photo</label>
<input type="file"
id="Photo"
name="Photo"
accept="image/gif, image/jpeg, image/png"
onchange="show(this)" />
</div>
<img id="onLoad"
src="#"
alt="photo is optional">
</div>...........some another info.
</form>
控制器:
[HttpPost]
public ActionResult Create(InventorViewModel inventor)
{
inventor.Photo = Request.Files["Photo"];
InventorEntity onAdding = new InventorEntity()
{
FirstName = inventor.FirstName,
SurName = inventor.SurName,
DateOfBirth = inventor.DateOfBirth,
Sex = inventor.Sex,
HigherEducation = inventor.HigherEducation == "on" ? true : false,
Description = inventor.Description,
Country = uow.UserBL.GetCounryById(int.Parse(inventor.Country)),
Photo = ImageConvertor.ConvertToBytes(inventor.Photo)
};
uow.UserBL.CreateInventor(onAdding);
return RedirectToAction("Index");
}
所以当我将此模型添加到数据库时,照片为 NULL。有任何想法吗?也许我应该改变一些东西(或一切xD)
【问题讨论】:
-
标签 enctype="multipart/form-data" 不应该在表单标签中吗?
-
是的!最后,谢谢伙计)
标签: asp.net-mvc