I want to upload an image into a database (ShoppingItems) OR save the image to a folder in my project and insert the path of the image into the db. Can anybody help? This is my code (view):
@using (Html.BeginForm("Index3", "Upload", FormMethod.Post))
{
@Html.TextBoxFor(x => x.Itemname, new { @class = "form-control", placeholder = "Item name", required = "required" })
<br />
@Html.TextBoxFor(x => x.Price, new { @class = "form-control", placeholder = "Item price", required = "required" })
<br />
@Html.TextBoxFor(x => x.Quantity, new { @class = "form-control", placeholder = "Item quantity"})
<br />
@Html.TextBoxFor(x => x.AuthorIdentity, new { @class = "form-control", placeholder = "Username", required = "required" })
<br />
// THIS IS WHERE MY IMAGE UPLOAD SHOULD BE
<br />
@Html.TextBoxFor(x => x.Category, new { @class = "form-control", placeholder = "Item category", required = "required" })
<br />
@Html.TextAreaFor(x => x.Description, new { @class = "form-control", placeholder = "Item description", required = "required" })
<br />
<input type="submit" class="btn btn-danger" value="Add" />
}
Controller:
public ActionResult Index3(ShoppingItem formModel);
{
using (var ctx = new GikGamerModelDataContext())
{
if (formModel == null)
return View();
ctx.ShoppingItems.InsertOnSubmit(formModel);
ctx.SubmitChanges();
}
return View();
}
My upload index (Index3) just shows text that says that your upload was successful or unsuccessful so I haven't added it :)