Anant Jain

Anant Jain

  • NA
  • 61
  • 8.2k

can't send file from view to controller

Sep 23 2015 6:00 AM
 If i add id="addEntry" in beginform then file are not saved in database but when i not write id="addentry" then file is  saved in database  so, can't understand what i do.
 
 
we used id="addentry" for barcode generate jquery .
 
 --------------------------------------------------------------
 in view :-
 
@using (Html.BeginForm("Create", "Euser", FormMethod.Post, new {id = "addEntry", enctype = "multipart/form-data"}))
 --------------------------------------------------------------
in Controller:-
 
public ActionResult Create(Table table, FormCollection fc, HttpPostedFileBase file)
 -----------------------------------------------------------------
Save Code:-
 
if (file != null && file.ContentLength > 0)
{
try
{
path = Path.Combine(Server.MapPath("~/Upload"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
tapalmaster.FileUploadPath = Path.GetFileName(file.FileName);
ViewBag.Message = "File uploaded successfully";
byte[] pic = new byte[file.ContentLength];
file.InputStream.Read(pic, 0, file.ContentLength);
}
catch (Exception ex)
{
ViewBag.Message = "ERROR:" + ex.Message.ToString();
}
}
else
{
ViewBag.Message = "You have not specified a file.";
}
 
Pz Give me a best solution 
 

Answers (1)