Guest User

Untitled

a guest
Dec 10th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <div class="result2">
  2. <table class="table table-bordered">
  3. <thead>
  4. <tr>
  5. <th>@Html.DisplayNameFor(m => m.ThermLossesDataInput.LyingTypeOne)</th>
  6. </tr>
  7. </thead>
  8. <tbody>
  9. @foreach (ThermLossesDataInput item in Model.ListThermLossesDataInputs)
  10. {
  11. <tr>
  12. <td>@item.LyingTypeOne</td>
  13. <td>
  14. <form method="post">
  15. //один из способов (пробовал через ViewBag)
  16. @{ ViewBag.ThermLossesDataInputId = item.ThermLossesDataInputId; }
  17. <input type="hidden" asp-for="@item.ThermLossesDataInputId" />
  18. <input type="button" class="btn btn-info" id="delete" value="del" />
  19. </form>
  20. </td>
  21. </tr>
  22. }
  23. </tbody>
  24. </table>
  25.  
  26. $(document).ready(function () {
  27. $('#delete').click(function () {
  28. $.ajax({
  29. type: 'POST',
  30. dataType: 'html',
  31. data: $('form').serialize(),
  32. // вариант с неправильными данными??? какой должен быть URL.Action?
  33. url: '@Url.Action("DeleteDataInputWaterPipelines", "ThermLosses", new { ViewBag.ThermLossesDataInputId })',
  34.  
  35. success: function (data) {
  36. $('#results').html(data);
  37. }
  38. });
  39. });
  40.  
  41. [HttpPost] // 0!!
  42. public IActionResult DeleteDataInputWaterPipelines(int ThermLossesDataInputId)
  43. {
  44.  
  45. WaterPipelineViewModel model = new WaterPipelineViewModel();
  46. ThermLossesDataInput thermLossesDataInput = _context.ThermLossesDataInputs.SingleOrDefault(m=>m.ThermLossesDataInputId == ThermLossesDataInputId);
  47. int thermLossesMainId = thermLossesDataInput.ThermLossesMainId;
  48.  
  49. _context.ThermLossesDataInputs.Remove(thermLossesDataInput);
  50. _context.SaveChanges();
  51.  
  52. model.ListThermLossesDataInputs = _context.ThermLossesDataInputs.Where(m => m.ThermLossesMainId == thermLossesMainId).ToList();
  53. return PartialView("_DataTable", model);
  54. }
  55.  
  56. <form method="post">
  57. <input type="hidden" value="@item.ThermLossesDataInputId" id="thdi"/>
  58. <input type="button" class="btn btn-info" id="delete" value="del" />
  59. </form>
  60.  
  61. $(document).ready(function () {
  62. $('#delete').click(function () {
  63. var id = $('#thdi').val();
  64. $.ajax({
  65. type: 'POST',
  66. dataType: 'html',
  67. data: { 'id' : id },
  68. url: '@Url.Action("DeleteDataInputWaterPipelines", "ThermLosses")',
  69. success: function (data) {
  70. $('#results').html(data);
  71. }
  72.  
  73. });
  74. });
Add Comment
Please, Sign In to add comment