【发布时间】:2014-07-12 09:21:44
【问题描述】:
我是 hamdling Entity Framework 的新手。我使用以下代码从 mvc4 中的文件上传按钮插入文件
public ActionResult Index(NewUserModel newUser)
{
Resume newuserResume = new Resume();
if (Request != null)
{
HttpPostedFileBase file = Request.Files["UploadedFile"];
if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
{
string fileName = file.FileName;
string fileextn = Path.GetExtension(fileName);
if (fileextn == ".pdf" || fileextn == ".doc")
{
string fileContentType = file.ContentType;
byte[] fileBytes = new byte[file.ContentLength];
file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
newuserResume.Resumes = fileBytes;
Hrentitymodel.Resumes.Add(newuserResume);
Hrentitymodel.SaveChanges();
}
else {
ViewBag.FileExtn = "File Should be in .doc or .pdf Format";
}
}
}
return View("Index");
}
它可以正常工作,这意味着文件以 Varbinary(max) 格式存储在 DB 中。 现在,如何在MVC4中使用实体框架从sql db查看和下载文件
【问题讨论】:
标签: c# sql entity-framework asp.net-mvc-4 entity-framework-4.1