@{ var itemList = (List<Item>)ViewData["itemsList"]; } <div class="row" style="margin-top: 10px;"> <div class="col-md-6"> @if (itemList != null) { var id = 0; <table class="table table-striped"> <thead> <tr> <th>#</th> <th></th> <th>Id</th> <th>Type</th> </tr> </thead> <tbody> @foreach (var result in itemsList) { <tr> <td>@(++id)</td> <td><input type="checkbox" value="true" @(result.Checked ? "checked" : "")></td> <td>@result.Id</td> <td>@result.Type</td> </tr> } </tbody> </table> } <div class="row justify-content-end" style="margin-top: 20px;"> <div class="col-md-2"> <form asp-controller="Control" asp-action="Remove" method="post"> <input type="hidden" name="tableName" value="table"/> <input type="hidden" name="items" value="@itemList"/> <div style="margin-left: -10px;" class="col-md-2"> <button class="btn btn-danger" title="Remove" type="submit">Remove</button> </div> </form> </div> </div> </div> </div>
[HttpPost] public async Task<IActionResult> Remove(string tableName, List<ChangeQueueItem> items) { try { var toDelete = items.Where(x => x.Checked == true); await _repository.RemoveFromQueue(toDelete, tableName); } catch (Exception e) { TempData["error"] = e.Message; } return RedirectToAction("Index"); }
<input type="hidden" name="items" value="@itemList"/>
[HttpGet] public async Task<IActionResult> Index() { var items = await _repository.GetAll(); ViewData["itemsList"] = items; ViewData["error"] = TempData["error"]; return View("Index"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)