'DemoEntities1 db = new DemoEntities1();'上的错误
namespace HRMS.Controllers
{
public class FileController : Controller
{
DemoEntities1 db = new DemoEntities1();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files, Tb_File objfile)
{
foreach (var file in files)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var filepath = Guid.NewGuid().ToString() + fileName;
var path = Path.Combine(Server.MapPath("~/uploads"), filepath);
file.SaveAs(path);
objfile.FileName = fileName;
objfile.Filepath = "~/uploads/" + filepath;
db.Tb_File.Add(objfile);
db.SaveChanges();
}
}
return View();
}
//download
public ActionResult Download()
{
var file = db.Tb_File.ToList();
return View(file);
}
public FileResult DownloadFile(string id)
{
int fid = Convert.ToInt32(id);
string filename = (from f in db.Tb_File
where f.Id == fid
select f.Filepath).First();
return File(filename, System.Net.Mime.MediaTypeNames.Application.Octet, filename);
}
}
}
答案 0 :(得分:0)
DemoEntities1是否在同一个项目中。可能你错过了使用声明。目前,您位于控制器命名空间中,您的实体可能位于不同的命名空间中。
在命名空间HRMS.Controllers上面添加以下行
using the namespaceforDemoentities1;