更新时间:2023-02-24 22:32:45
命名空间Template.MVC5.Controllers
{
公共类FileLoadController:Controller
{
private readonly FileloadBusiness _db = new FileloadBusiness();
public ActionResult Index()
{
var x = new FileloadBusiness();
return View( x.GetAll());
}
public ActionResult创建()
{
返回查看();
}
[HttpGet]
public ActionResult Uploaded()
{
ViewBag.Message =doc;
返回查看();
}
[HttpPost]
public ActionResult Uploaded(Fileload查看型号)
{
返回RedirectToAction(CustHome,客户);
}
[HttpPost]
公共ActionResult创建(FileloadView doc)
{
试试
{
_db.Insert(doc);
返回RedirectToAction(Uploaded);
}
catch(例外e)
{
返回查看() ;
}
}
DataContext db = new DataContext();
公共ActionResult下载()
{
返回查看(_db.GetAll());
}
public FileContentResult FileDownload(int? id)
{
byte [] fileData;
string fileName;
var x = new FileloadBusiness();
var fileRecord = db.FileLoads.Find(id);
fileData =(byte [])fileRecord.File.ToArray();
fileName = fileRecord.FileName;
返回文件(fileData,text,fileName);
}
}
}
namespace Template.MVC5.Controllers
{
public class FileLoadController : Controller
{
private readonly FileloadBusiness _db = new FileloadBusiness();
public ActionResult Index()
{
var x = new FileloadBusiness();
return View(x.GetAll());
}
public ActionResult Creating()
{
return View();
}
[HttpGet]
public ActionResult Uploaded()
{
ViewBag.Message = "doc";
return View();
}
[HttpPost]
public ActionResult Uploaded(FileloadView model)
{
return RedirectToAction("CustHome", "Customer");
}
[HttpPost]
public ActionResult Creating(FileloadView doc)
{
try
{
_db.Insert(doc);
return RedirectToAction("Uploaded");
}
catch (Exception e)
{
return View();
}
}
DataContext db = new DataContext();
public ActionResult Download()
{
return View(_db.GetAll());
}
public FileContentResult FileDownload(int? id)
{
byte[] fileData;
string fileName;
var x = new FileloadBusiness();
var fileRecord = db.FileLoads.Find(id);
fileData = (byte[])fileRecord.File.ToArray();
fileName = fileRecord.FileName;
return File(fileData, "text", fileName);
}
}
}