I am building a simple MVC CRUD without using a database, but just making methods in a Repository model class.
To make it easier to understand i have 2 model classes. MyNote in which i have some properties and NoteRepository in which i have a list with the properties.
Then I’ve made a NoteController and i have already made Get and Create methods, but i can’t seem to figure out what to write to make an Edit and Delete method? Hope you guys can help.
Here you will see some of the code from my project:
@using Agency.Core.Models
@model Portfolio
<div class="container">
<form method="post" asp-action="DeletePortfolio" class="card" style="width: 18rem;">
<img src="~/Upload/Portfolio/@Model.ImageUrl" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">@Model.Title</h5>
<p class="card-text">@Model.Subtitle</p>
<input asp-for="@Model.Id" hidden value="@Model.Id"/>
<a class="btn btn-primary" asp-action="Index" asp-controller="Portfolio"> Go back</a>
<button type="submit" > Delete</button>
</div>
</form>
</div>
@using Agency.Core.Models
@model Portfolio
<div class="container">
<div class="row">
<form method="post" enctype="multipart/form-data">
<div class="container">
<label asp-for="Title"> </label>
<input asp-for="Title" />
<span asp-validation-for="Title"> </span>
</div>
<div class="container">
<label asp-for="Subtitle"> </label>
<input asp-for="Subtitle" />
<span asp-validation-for="Subtitle"> </span>
</div>
<div class="container">
<label asp-for="ImageFile"> </label>
<input asp-for="ImageFile" />
<span asp-validation-for="ImageFile"> </span>
</div>
<button type="submit"> Submit</button>
</form>
</div>
</div>
@using Agency.Core.Models
@model List<Portfolio>
@{
int count = 0;
}
<div class="container">
<table class="table">
<h1>
portfolios
</h1>
<a class="btn btn-primary" asp-action="Create" asp-controller="Portfolio">Create</a>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Title</th>
<th scope="col">Subtitle</th>
<th scope="col">Image</th>
</tr>
</thead>
<tbody>
@foreach(var item in Model){
<tr>
<th scope="row">@item.Id</th>
<td>@item.Title</td>
<td>@item.Subtitle</td>
<td>
<div width:100px>
<img src="~/Upload/Portfolio/@item.ImageUrl" />
</div>
</td>
<td>
<a class="btn btn-warning" asp-action="Update" asp-controller="Portfolio" asp-route-id="@item.Id"> Update</a>
<a class="btn btn-danger" asp-action="Delete" asp-controller="Portfolio" asp-route-id="@item.Id"> Delete</a>
</td>
</tr>
}
</tbody>
</table>
</div>
here is the repository class with the list and the method for the create method.
and please, ask if i have missed something! Thank you 🙂
user54321 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1