I would appreciate if anyone could help me with this. I have input file control in a form in a view and when someone picks a picture and clicks the submit button on the form, that file has to be saved in /Pictures folder in the application and file path needs to be saved in SQL database as string (like: /Pictures/filename).
Models class part:
[Table("Automobil")]
public partial class Automobil
{ .....
[Required]
[StringLength(30)]
public string Fotografija{ get; set; }
......
View (Create) file part:
@using (Html.BeginForm("Create", "Automobili", FormMethod.Post, new { enctype = "multipart/form-data" }))
....
<div class="form-group">
<div class="editor-field">
@Html.TextBoxFor(model => model.Fotografija, new { type = "file" })
@Html.ValidationMessageFor(model => model.Fotografija, "", new { @class = "text-danger" })
</div>
</div>
....
Controller part:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "AutomobilID,Marka,Model,Godiste,Zapremina_motora,Snaga,Gorivo,Karoserija,Fotografija,Opis,Cena,Kontakt")] Automobil automobil)
{
if (ModelState.IsValid)
{
db.Automobils.Add(automobil);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(automobil);
}
What do I need to do so the photo(Fotografija) could be saved in the application folder Pictures, and file path in SQL base (like /Pictures/filename)?
Thank you in advance for helping the beginner.