Anonymous
Вставить изображение в базу данных с помощью С#
Сообщение
Anonymous » 26 окт 2025, 16:25
Я хочу загрузить изображение в базу данных (ShoppingItems) ИЛИ сохранить изображение в папке моего проекта и вставить путь к изображению в базу данных.
Это мой код (просмотр):
Код: Выделить всё
@using (Html.BeginForm("Index3", "Upload", FormMethod.Post))
{
@Html.TextBoxFor(x => x.Itemname, new { @class = "form-control", placeholder = "Item name", required = "required" })
@Html.TextBoxFor(x => x.Price, new { @class = "form-control", placeholder = "Item price", required = "required" })
@Html.TextBoxFor(x => x.Quantity, new { @class = "form-control", placeholder = "Item quantity"})
@Html.TextBoxFor(x => x.AuthorIdentity, new { @class = "form-control", placeholder = "Username", required = "required" })
// THIS IS WHERE MY IMAGE UPLOAD SHOULD BE
@Html.TextBoxFor(x => x.Category, new { @class = "form-control", placeholder = "Item category", required = "required" })
@Html.TextAreaFor(x => x.Description, new { @class = "form-control", placeholder = "Item description", required = "required" })
}
Контроллер:
Код: Выделить всё
public ActionResult Index3(ShoppingItem formModel);
{
using (var ctx = new GikGamerModelDataContext())
{
if (formModel == null)
return View();
ctx.ShoppingItems.InsertOnSubmit(formModel);
ctx.SubmitChanges();
}
return View();
}
Мой индекс загрузки (Index3) просто показывает текст, сообщающий об успешной или неудачной загрузке, поэтому я его не добавлял.
Подробнее здесь:
https://stackoverflow.com/questions/413 ... th-c-sharp
1761485117
Anonymous
Я хочу загрузить изображение в базу данных (ShoppingItems) ИЛИ сохранить изображение в папке моего проекта и вставить путь к изображению в базу данных. Это мой код (просмотр): [code]@using (Html.BeginForm("Index3", "Upload", FormMethod.Post)) { @Html.TextBoxFor(x => x.Itemname, new { @class = "form-control", placeholder = "Item name", required = "required" }) @Html.TextBoxFor(x => x.Price, new { @class = "form-control", placeholder = "Item price", required = "required" }) @Html.TextBoxFor(x => x.Quantity, new { @class = "form-control", placeholder = "Item quantity"}) @Html.TextBoxFor(x => x.AuthorIdentity, new { @class = "form-control", placeholder = "Username", required = "required" }) // THIS IS WHERE MY IMAGE UPLOAD SHOULD BE @Html.TextBoxFor(x => x.Category, new { @class = "form-control", placeholder = "Item category", required = "required" }) @Html.TextAreaFor(x => x.Description, new { @class = "form-control", placeholder = "Item description", required = "required" }) } [/code] Контроллер: [code]public ActionResult Index3(ShoppingItem formModel); { using (var ctx = new GikGamerModelDataContext()) { if (formModel == null) return View(); ctx.ShoppingItems.InsertOnSubmit(formModel); ctx.SubmitChanges(); } return View(); } [/code] Мой индекс загрузки (Index3) просто показывает текст, сообщающий об успешной или неудачной загрузке, поэтому я его не добавлял. Подробнее здесь: [url]https://stackoverflow.com/questions/41313735/insert-image-into-database-with-c-sharp[/url]