Submit Form in Razor view (edit)
@section Scripts { <script type="text/javascript"> $(document).ready(function () { $('form').submit(function (event) { var self = this; debugger; event.preventDefault(); //prevent default action
var post_url = $(self).attr("action"); //get form action url
var request_method = $(self).attr("method"); //get form GET/POST method $('<input />').attr('type', 'hidden') .attr('name', "id") .attr('value', "1") .appendTo(self); var form_data = $(self).serialize(); //Encode form elements for submission $.ajax({ url: post_url, type: request_method, data: form_data }).done(function (response) { alert('success'); //$("#server-results").html(response); }); }); }); </script> }
Articles
http://techfunda.com/howto/97/form-based-razor-view
https://www.aspsnippets.com/Articles/ASPNet-MVC-Form-Submit-Post-example.aspx
https://www.c-sharpcorner.com/article/asp-net-mvc5-razor-ajax-form-control/ (HAY)
https://www.twilio.com/blog/2017/09/everything-you-ever-wanted-to-know-about-secure.html-forms.html (HAY)
http://javascript-coder.com/javascript-form/javascript-form-submit.phtml