I believe this would help
public void Insert(FileloadView doc)
{
using (var rep = new FileloadRepository())
{
rep.Insert(ConvertToDocuments(doc));
}
}
private static FileLoad ConvertToDocuments(FileloadView doc)
{
FileLoad FileUplodModel = new FileLoad();
foreach (var item in doc.File)
{
byte [] uploadFile = new byte[item.InputStream.Length];
item.InputStream.Read(uploadFile, 0, uploadFile.Length);
FileUplodModel.FileName = item.FileName;
FileUplodModel.File = uploadFile;
}
return FileUplodModel;
}
and then apply the following code in the controller
private readonly FileloadBusiness _db = new FileloadBusiness();
public ActionResult Creating()
{
return View();
}
[HttpPost]
public ActionResult Creating(FileloadView doc)
{
try
{
_db.Insert(doc);
return RedirectToAction("Uploaded");
}
catch (Exception e)
{
return View();
}
}
And add this to your View
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
}