Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
Webinar_51
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexey Goikolov
Webinar_51
Commits
de87b539
Commit
de87b539
authored
Mar 31, 2021
by
Alexey Goikolov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил 2 экшна Delete и ConfirmDelete для удаления телефона. Создал представление Delete.cshtml
parent
de48ab66
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
PhonesController.cs
Lesson49/Controllers/PhonesController.cs
+24
-0
Delete.cshtml
Lesson49/Views/Phones/Delete.cshtml
+13
-0
No files found.
Lesson49/Controllers/PhonesController.cs
View file @
de87b539
...
...
@@ -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
Lesson49/Views/Phones/Delete.cshtml
0 → 100644
View file @
de87b539
@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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment