Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //пик 1
- <form method="delete" asp-route="ProductCatalogSingle">
- <input hidden type="number" name="Id" value="@Model.Id" />
- <input type="submit" class="btn btn-dark" value="Delete" />
- </form>
- //пик 2
- // Controller have [Route("product-catalog")] attribute
- [HttpDelete("product", Name = "ProductCatalogSingle")]
- public async Task<IActionResult> DeleteSingleItem(int id)
- {
- // business-logic part responsible for data managment
- await logic.RemoveDataModelAsync(new ProductCatalog { Id = id });
- return RedirectToRoute("ProductCatalogAll");
- }
- // other action with same route, but different method
- [HttpGet("product", Name = "ProductCatalogSingle")]
- public async Task<IActionResult> SingleItem(int id)
- {...}
- // пик 3
- // "/product-catalog/product" and "@Url.Link("ProductCatalogSingle", null)" вместо url
- @section scripts{
- <script>
- document.forms[0].onsubmit = () => {
- let formData = new FormData(document.forms[0]);
- fetch(url, {
- method: "DELETE",
- body: new URLSearchParams(formData)
- })
- .then(() => {
- alert('Deleted using Fetch');
- });
- return true;
- };
- </script>
- // пик 4
- @section scripts{
- <script>
- $(function () {
- $('#submit').on('click', function (evt) {
- evt.preventDefault();
- $.ajax({
- type: "DELETE",
- url: '/product-catalog/product?id=4001'
- });
- });
- });
- </script>
- // Ажакс анобструксив
- @section scripts{
- <script src="~/lib/jquery-ajax-unobtrusive/jquery.unobtrusive-ajax.js"></script>
- }
- <form method="delete" asp-route="ProductCatalogSingle" data-ajax="true" data-ajax-method="delete">
- <input hidden type="number" name="productId" value="@item.ProductId" />
- <input type="submit" class="btn btn-dark" value="Delete" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement