I want to insert destination files to database like php do..
but I get error, in database insert System.Web.HttpPostedFileWrapper
not my desination files, but files success upload to my folder..
and how do I download it in Razor View
this for my controller
public class HomeController : Controller
{
RahmanEntities db = new RahmanEntities();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(updown viewModel)
{
// extract only the filename
var fileName = Path.GetFileName(Request.Files[0].FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
try
{
if (System.IO.File.Exists(path))
{
ModelState.AddModelError("uploadError", "Duplicate Data");
}
else
{
Request.Files[0].SaveAs(path);
}
}
catch (Exception)
{
ModelState.AddModelError("uploadError", "Can't save file to disk");
}
if (ModelState.IsValid)
{
// put your logic here
updown item = new updown();
item.upload = viewModel.upload;
db.updowns.Add(item);
db.SaveChanges();
return RedirectToAction("Index", "Home");
}
return View(viewModel);
}
public ActionResult List()
{
var tes = db.updowns.ToList();
return View(tes);
}
}
and then this for my Razor View Upload
@model updownload.Models.updown
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div>
@Html.ValidationMessage("uploadError")<br />
<input type="file" name="upload" id="upload" />
</div>
<button type="submit">Upload</button>
}
I dont know create Razor View
for Download
can someone help fix me code..
Sorry for my bad english
this for my model
public partial class updown
{
public int id { get; set; }
public string upload { get; set; }
}