Я смотрю несколько учебных пособий по изучению ASP.NET Core. Я создаю веб-приложение MVC. На веб-сайте у меня есть опция редактирования продуктов. Когда я нажимаю кнопку редактирования, она переходит по этому URL;
"https://localhost:5001/Admin/Products/Edit1"
, и это дает мне ошибку. Вместо этого оно должно перейти к
" https://localhost:5001/Admin/Products/Edit/1"
Но это не так. Как можноя это исправлю?
Product / Index.cshtml
@model IEnumerable<NewGraniteHouse.Models.Products>
@{
ViewData["Title"] = "Index";
}
<br /><br />
<div class="row">
<div class="col-6">
<h2 class="text-info">Product List</h2>
</div>
<div class="col-6 text-right">
<a asp-action="Create" class="btn btn-info"><i class="fas fa-plus"></i> New Product</a>
</div>
</div>
<br />
<div>
<table class="table table-striped border">
<tr class="table-info">
<th>
@Html.DisplayNameFor(m => m.Name)
</th>
<th>
@Html.DisplayNameFor(m => m.Price)
</th>
<th>
@Html.DisplayNameFor(m => m.Available)
</th>
<th>
@Html.DisplayNameFor(m => m.ProductTypes)
</th>
<th>
@Html.DisplayNameFor(m => m.SpecialTags)
</th>
<th></th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(m => item.Name)
</td>
<td>
@Html.DisplayFor(m => item.Price)
</td>
<td>
@Html.DisplayFor(m => item.Available)
</td>
<td>
@Html.DisplayFor(m => item.ProductTypes.Name)
</td>
<td>
@Html.DisplayFor(m => item.SpecialTags.Name)
</td>
<td>
<partial name="_TableButtonPartial" model="item.Id" />
</td>
</tr>
}
</table>
</div>
Product / Edit.cshtml
@model NewGraniteHouse.Models.ViewModel.ProductsViewModel
@using NewGraniteHouse.Extensions
@{
ViewData["Title"] = "Edit";
}
<br />
<h2 class="text-info">Edit Product</h2>
<form method="post" enctype="multipart/form-data">
<div class="p-4 border rounded row">
<input hidden asp-for="Products.Id" />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="col-8">
<div class="form-group row">
<div class="col-4">
<label asp-for="Products.Name"></label>
</div>
<div class="col-8">
<input asp-for="Products.Name" class="form-control" />
</div>
<span asp-validation-for="Products.Name" class="text-danger"></span>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="Products.Price"></label>
</div>
<div class="col-8">
<input asp-for="Products.Price" class="form-control" />
</div>
<span asp-validation-for="Products.Price" class="text-danger"></span>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="Products.Image"></label>
</div>
<div class="col-8">
<input type="file" name="files" class="form-control" />
</div>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="ProductTypes"></label>
</div>
<div class="col-8">
<select asp-for="@Model.Products.ProductTypeId" asp-items="Model.ProductTypes.ToSelectListItem(Model.Products.ProductTypeId)"
class="form-control"></select>
</div>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="SpecialTags"></label>
</div>
<div class="col-8">
<select asp-for="@Model.Products.SpecialTagsId" asp-items="Model.SpecialTags.ToSelectListItem(Model.Products.SpecialTagsId)"
class="form-control"></select>
</div>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="Products.ShadeColor"></label>
</div>
<div class="col-8">
<input asp-for="Products.ShadeColor" class="form-control" />
</div>
<span asp-validation-for="Products.ShadeColor" class="text-danger"></span>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="Products.Available"></label>
</div>
<div class="col-8">
<input type="checkbox" asp-for="Products.Available" />
</div>
</div>
</div>
<div class="col-1">
</div>
<div class="col-3">
<img src="@Model.Products.Image" width="100%" style="border-radius:5px; border:1px solid #bbb9b9; " />
</div>
<br />
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Update" />
<a asp-action="Index" class="btn btn-success">Back to List</a>
</div>
</div>
</form>
@section Scripts{
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
_TableButtonPartial.cshtml
@model int
@*
For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
<td style="width:150px">
<div class="btn-group" role="group" ">
<a type="button" class="btn btn-primary" href="@Url.Action("Edit"+Model)">
<i class="fas fa-edit"></i>
</a>
<a type="button" class="btn btn-success" href="@Url.Action("Details"+Model)">
<i class="fas fa-list-ul"></i>
</a>
<a type="button" class="btn btn-danger" href="@Url.Action("Delete"+Model)">
<i class="fas fa-trash-alt"></i>
</a>
</div>
</td>
Редактировать: Добавлены файлы cshtml.