I am trying to remove records from database using Entity Framework.
This is the code:
Controller:
[HttpPost]
public ActionResult DeleteProduct(int?id)
{
Product prd = db.Products.Find(id);
db.Products.Remove(prd);
db.SaveChanges();
return View();
}
View:
<form method="post" enctype="multipart/form-data">
<div class="row ">
@foreach (var product in Model)
{
<div class="col-md-6 col-lg-4 Products">
<figure class="card card-product mehsul">
<div class="img-wrap"> <img class="img-fluid mehsulimg" src="@product.PhotoProducts.First().ImageName" alt=""> </div>
<div class="handhover">
<img class="img-fluid" src="@product.PhotoProducts.Last().ImageName" alt="">
</div>
<figcaption class="info-wrap">
<a href="/Shop/Product/@product.id">@product.ProdName</a>
<p class="desc">Some small description goes here</p>
</figcaption>
<div class="bottom-wrap">
<a href="" class="m-2 btn btn-sm btn-primary float-right">Paylash</a>
<a id="DelProd" href="/ProductAd/DeleteProduct/@product.id" class="m-2 btn btn-sm btn-primary float-right">Sil</a>
<div class="price-wrap h5">
<span class="price-new">$1280</span> <del class="price-old">$1980</del>
</div> <!-- price-wrap.// -->
</div> <!-- bottom-wrap.// -->
</figure>
</div> <!-- col // -->
}
</div>
</form>
But I am getting this error:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.Requested URL: /ProductAd/DeleteProduct/1
atag does an HttpGet.