@manhng

Welcome to my blog!

Submit Form in Razor view

April 30, 2019 16:16

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

https://docs.microsoft.com/en-us/aspnet/web-pages/overview/ui-layouts-and-themes/4-working-with-forms

https://blog.michaelckennedy.net/2012/11/13/improve-perceived-performance-of-asp-net-mvc-websites-with-async-partialviews/

https://jonhilton.net/2017/08/17/how-to-get-data-from-an-html-form-to-your-asp.net-mvc-core-controller/

Categories

Recent posts