actually I can not want to visible my id when I was something delete.so I want to slug here.but can not understand how I modify or convert id to slug type. here is my code:
startup.cs
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area=Customer}/{controller=Home}/{action=Index}/{id?}"
);
});
[HttpGet]
public ActionResult Delete(int? id)
{
if (id == null)
{
NotFound();
}
var product = _db.Spray.Include(c => c.ProductTypes).FirstOrDefault(c => c.Id == id);
if (product == null)
{
return NotFound();
}
return View(product);
}
[HttpPost]
[ActionName("Delete")] //DeleteConfirm nam ke delete namei chinbo
public async Task<IActionResult> DeleteConfirm(int? id)
{
if (id == null)
{
return NotFound();
}
var product = _db.Spray.FirstOrDefault(c => c.Id == id);
if (product == null)
{
return NotFound();
}
_db.Spray.Remove(product);
await _db.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
}
}
Delete.cshtml
form asp-action="Delete" method="post" enctype="multipart/form-data">
<div class="p-4 rounded border-row">
<div asp-validation-summary="ModelOnly" class="text-danger">
</div>
<div>
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="Name"></label>
</div>
<div class="col-8">
<input type="hidden" asp-for="Id" />
<input asp-for="Name" readonly="readonly" class="form-control" />
</div>
<span asp-validation-for="Name" class="text-danger"></span>
</div>
I have no idea to add how to add slug. I don't want to see my visible id for that I tried to make its slug. but I don't understand actually how to take process. I am beginner, please help anyone.