Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @section scripts
- {
- @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")
- @Scripts.Render("~/Scripts/jquery.validate.min.js")
- @Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js");
- @Scripts.Render("~/Scripts/moment.js")
- <script>
- $(document).on('submit', '#contractorForm', function (e) {
- e.preventDefault();
- var form = $("#contractorForm");
- form.validate();
- var action = '@Url.Action("Add")';
- console.log(action);
- $.ajax({
- url: action,
- type: 'post',
- data: form.serialize(),
- success: function (data)
- {
- $('#successDiv').show();
- $('#errorDiv').hide();
- $('#successText').html(data);
- window.scrollTo(0, 0);
- },
- error: function (data)
- {
- $('#successDiv').hide();
- $('#errorDiv').show();
- var html = '';
- for (var k in data.responseJSON) {
- html += '<p>' + data.responseJSON[k] + '</p>'
- }
- $('#errorText').html(html);
- window.scrollTo(0, 0);
- $(".field-validation-error").each(function () {
- $(this).closest(".form-group").addClass("has-error");
- });
- }
- });
- return false;
- });
- </script>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement