Guest User

Untitled

a guest
Nov 2nd, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. @foreach (var b in ViewBag.Workers)
  2. {
  3. <tr>
  4. <td><p>@b.Surname</p></td>
  5. <td><p>@b.Name</p></td>
  6. <td><p>@b.Patronymic</p></td>
  7. <td><p>@b.Position</p></td>
  8. <td>
  9. <form method="post" action="">
  10. <input type="hidden" value="@b.Id" name="WorkerId" />
  11. <input type="submit" value="Удалить" />
  12. </form>
  13. </td>
  14. </tr>
  15. }
  16.  
  17. @foreach (var b in ViewBag.Workers)
  18. {
  19. <tr>
  20. <td><p>@b.Surname</p></td>
  21. <td><p>@b.Name</p></td>
  22. <td><p>@b.Patronymic</p></td>
  23. <td><p>@b.Position</p></td>
  24. <td>
  25. <button data-id="@b.Id">Удалить</button>
  26. </td>
  27. </tr>
  28. }
  29.  
  30. ...
  31.  
  32. <script>
  33. 'use strict';
  34.  
  35. var urlToAction = '@Url.Action("RemoveItPlease", "Home")';
  36.  
  37. $(document).ready(function() {
  38. $('table button').click(function (e){
  39. var workerId = $(e.target).data('id');
  40.  
  41. $.ajax({
  42. url: urlToAction,
  43. method: 'POST',
  44. data: { id: workerId }
  45. });
  46. });
  47. });
  48.  
  49. </script>
  50.  
  51. ....
  52.  
  53. public HomeController: Controller {
  54. [HttpPost]
  55. public ActionResult RemoveItPlease(int id) {
  56. ...
  57. }
  58. }
Add Comment
Please, Sign In to add comment