Using this code with .Net MVC i am saving employees pic you can try this code withOut javascript
View Code
@using (Html.BeginForm("Create", "Employees", FormMethod.Post, new { enctype =
"multipart/form-data" }))
{
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input id="AttachmentName" name="AttachmentName" type="file">
</div>
</div>
</div>
}
Controller code
[HttpPost]
public ActionResult Create(EmployeeClass employeeClass, HttpPostedFileBase AttachmentName)
{
string newProfileName = "";
if (AttachmentName != null)
{
HttpPostedFileBase AttachmentNameFile = Request.Files["AttachmentName"];
string productImageExt = Path.GetExtension(AttachmentNameFile.FileName);
newProfileName = DateTime.Now.ToString("MMddyyHHmmss") + productImageExt;
var saveimage = SaveImage(AttachmentNameFile, newProfileName);
}
}
public bool SaveImage(HttpPostedFileBase AttachmentNameFile, string FileName)
{
if (AttachmentNameFile.FileName != "")
{
string folderexist = Server.MapPath("~/images/ProfileImage/");
bool isExist = System.IO.Directory.Exists(folderexist);
if (!isExist)
{
System.IO.Directory.CreateDirectory(folderexist);
}
AttachmentNameFile.SaveAs(folderexist + FileName);
}
return true;
}