Не могу сохранить изменение, сделанные на форме View

Есть 2 метода для открытия View по id и второй для обновления данных. Всё это находиться в ProductsViewController.

        [HttpPost]
        public IActionResult Edit(ProductDTO product)
        {
            _productWorker.Edit(product);
            return View();
        }
        [HttpGet("edit/{id}")]
        public IActionResult Edit(int id)
        {
            return View("Edit", new ProductDTO(_productWorker.GetById(id)));
        }

Также есть View. При изменении и попытке сохранения данных я получаю HTTP ERROR 405 и собственно ничего не происходит, даже вызова метода POST запроса.

@model DeliveryApp.DAL.DTO.ProductDTO
@{
    ViewData["Title"] = "Edit";
}

<h1>Edit</h1>

<h2>@Model.Name</h2>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Edit" asp-controller="ProductsView" method="post">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <input type="hidden" asp-for="Id" />
            <div class="form-group">
                @Html.EditorFor(model => model.Name)
                @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
            </div>
            <div class="form-group">
                @Html.EditorFor(model => model.Description)
                @Html.LabelFor(model => model.Description, new { @class = "control-label col-md-2" })
            </div>
            <div class="form-group">
                @Html.EditorFor(model => model.Price)
                @Html.LabelFor(model => model.Price, new { @class = "control-label col-md-2" })
            </div>
            <div class="form-group">
                @Html.EditorFor(model => model.VendorId)
                @Html.LabelFor(model => model.VendorId, new { @class = "control-label col-md-2" })
            </div>
            <div class="form-group">
                @Html.EditorFor(model => model.TypeId)
                @Html.LabelFor(model => model.TypeId, new { @class = "control-label col-md-2" })
            </div>
            <div class="form-group">
                @Html.EditorFor(model => model.CategoryId)
                @Html.LabelFor(model => model.CategoryId, new { @class = "control-label col-md-2" })
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

<a href="/mvc/products">Go back to Index</a>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

Как я могу подружить нажатие на Save и дальнейшее обновление данных в базе?


Ответы (0 шт):