Mode:-
View:-
@using (Html.BeginForm("Patner", "Home", FormMethod.Post, new { enctype = "multipart/form-data"}))
public class Patner
{
[Key]
public int PatnerId { get; set; }
[Required(ErrorMessage = "Patner name is required")]
[Display(Name="Patner Name: ")]
public string PatnerName { get; set; }
[Display(Name = "Id Proof: ")]
public string IdProof { get; set; }
[Display(Name = "Address Proof: ")]
public string AddressProof { get; set; }
}View:-
@using (Html.BeginForm("Patner", "Home", FormMethod.Post, new { enctype = "multipart/form-data"}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.PatnerName, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.PatnerName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PatnerName, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.IdProof, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.LabelFor(model => model.AddressProof, htmlAttributes: new { @class = "control-label col-md-2" })
}
Controller :-
[HttpPost]
public ActionResult Patner(Patner patner, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
string path = Path.Combine(Server.MapPath("~/Upload"), Path.GetFileName(file.FileName));
file.SaveAs(path);
using (SolarDbContext db = new SolarDbContext())
{
patner.IdProof = file.FileName;
patner.AddressProof= ?
db.Patners.Add(patner);
db.SaveChanges();
}
ModelState.Clear();
ViewBag.Message = "Data successfully saved.";
}
return View();
}
How to upload both file with data?
Thanks
Manamohan


Manmohan JhaPosted Aug 24, 2016, 1:40 AM
but above code for multiple same file upload not for different file upload.
Manas MohapatraPosted Aug 19, 2016, 8:39 AM
Vinay SinghPosted Aug 19, 2016, 7:58 AM
Joginder BangerPosted Aug 19, 2016, 6:09 AM