Commit de87b539 authored by Alexey Goikolov's avatar Alexey Goikolov

Добавил 2 экшна Delete и ConfirmDelete для удаления телефона. Создал представление Delete.cshtml

parent de48ab66
......@@ -49,5 +49,29 @@ namespace Lesson49.Controllers
return RedirectToAction("Index");
}
public IActionResult Delete(int id)
{
Phone phone = _db.Phones.FirstOrDefault(p => p.Id == id);
if (phone != null)
return View(phone);
return NotFound();
}
[HttpPost]
[ActionName("Delete")]
public IActionResult ConfirmDelete(int id)
{
Phone phone = _db.Phones.FirstOrDefault(p => p.Id == id);
if (phone != null)
{
_db.Phones.Remove(phone);
_db.SaveChanges();
return RedirectToAction("Index");
}
return NotFound();
}
}
}
\ No newline at end of file
@model Phone
@{
ViewBag.Title = "Подтверждение удаления";
Layout = "_Layout";
}
<h2>Вы уверены, что хотите удалить @Model.Name ?</h2>
<form asp-action="Delete" asp-controller="Phones" asp-route-id="@Model.Id" method="post">
<button class="btn-danger" type="submit">Да</button>
<a class="btn btn-primary" asp-action="Index">Нет</a>
</form>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment