Advertisement
Koelion

Untitled

Oct 10th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. @section scripts
  2. {
  3. @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")
  4. @Scripts.Render("~/Scripts/jquery.validate.min.js")
  5. @Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js");
  6. @Scripts.Render("~/Scripts/moment.js")
  7.  
  8. <script>
  9. $(document).on('submit', '#contractorForm', function (e) {
  10. e.preventDefault();
  11. var form = $("#contractorForm");
  12. form.validate();
  13. var action = '@Url.Action("Add")';
  14. console.log(action);
  15. $.ajax({
  16. url: action,
  17. type: 'post',
  18. data: form.serialize(),
  19. success: function (data)
  20. {
  21. $('#successDiv').show();
  22. $('#errorDiv').hide();
  23. $('#successText').html(data);
  24. window.scrollTo(0, 0);
  25. },
  26. error: function (data)
  27. {
  28. $('#successDiv').hide();
  29. $('#errorDiv').show();
  30. var html = '';
  31. for (var k in data.responseJSON) {
  32. html += '<p>' + data.responseJSON[k] + '</p>'
  33. }
  34. $('#errorText').html(html);
  35. window.scrollTo(0, 0);
  36. $(".field-validation-error").each(function () {
  37. $(this).closest(".form-group").addClass("has-error");
  38. });
  39. }
  40. });
  41. return false;
  42. });
  43. </script>
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement