hi have shown code edit image in controller.
public partial class Itemtable
{
public int ItemId { get; set; }
public int CategoryId { get; set; }
public int ProducerId { get; set; }
public string Title { get; set; }
public decimal Price { get; set; }
public string ItemUrl { get; set; }
public string CategoryName { get; set; }
public string Productname { get; set; }
public HttpPostedFileBase Imagefile { get; set; }
public HttpPostedFileBase Imagefile1 { get; set; }
public ActionResult Edit([Bind(Include = "ItemId,CategoryId,ProducerId,Title,Price,ItemUrl")] Itemtable itemtable)
{
List allcategory = new List();
foreach (var role in db.categoryTables)
{
allcategory.Add(new SelectListItem { Text = role.CategoryName, Value = role.CategoryId.ToString() });
}
ViewBag.category = allcategory;
List allproduct = new List();
foreach (var role in db.prodtbls)
{
allproduct.Add(new SelectListItem { Text = role.Productname, Value = role.ProducerId.ToString() });
}
ViewBag.product = allproduct;
string filename1 = Path.GetFileNameWithoutExtension(itemtable.Imagefile1.FileName);
string extension1 = Path.GetExtension(itemtable.Imagefile1.FileName);
filename1 = filename1 + extension1;
itemtable.ItemUrl = "~/Image/" + filename1;
filename1 = Path.Combine(Server.MapPath("~/Image/"), filename1);
itemtable.Imagefile1.SaveAs(filename1);
//if (ModelState.IsValid)
//{
// itemtable.ItemUrl = null;
db.Entry(itemtable).State = EntityState.Modified;
db.SaveChanges();
ModelState.Clear();
// return RedirectToAction("Index");
//}
return View(itemtable);
}
edit view page
@model onlineshopping_sonal.Models.Itemtable
@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
Edit
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
Itemtable
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ItemId)
@Html.LabelFor(model => model.CategoryId, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownList("CategoryId", (IEnumerable)ViewBag.category, "-- Select --")
@Html.ValidationMessageFor(model => model.CategoryId, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.ProducerId, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownList("ProducerId", (IEnumerable)ViewBag.product, "-- Select --")
@Html.ValidationMessageFor(model => model.ProducerId, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.ItemUrl, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.ValidationMessageFor(model => model.ItemUrl, "", new { @class = "text-danger" })
}
@Html.ActionLink("Back to List", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
} ..
please share edit coded image full folder to us, regards
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Salman BegPosted Mar 8, 2019, 9:22 AM