How To Create jQuery Ajax Post Method In ASP.NET MVC

In this article we will learn how to create the simple jQuery Ajax  Post method in ASP.NET MVC which will post the data to the server method .
Lest consider the scenario we have action method in named Addemployee in Home controller and we wants to pass input values to the controller .Then jQuery function will be look like as follows.
$(document).ready(function () {
        $("#btnSave").click(function () {
            $.ajax(
            {
                type: "POST", //HTTP POST Method
                url: "Home/AddEmployee", // Controller/View 
                data: { //Passing data
                    Name: $("#txtName").val(), //Reading text box values using Jquery 
                    City: $("#txtAddress").val(),
                    Address: $("#txtcity").val()
                }

            });

        });
    });
Note
  • To work with jQuery we need to reference of jQuery library .You can use following CDN jQuery library from any provider such as Microsoft,Google or jQuery .
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
To use above jQuery library you need an active internet connection , You can download and use it as offline .You need to be add reference as like below.
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
From preceding example we have learned how to create simple jQuery Ajax post method in ASP.NET MVC.
Summary
I hope this article is useful for all readers, if you have a suggestion then please contact me.
 To learn ASP.NET MVC step by step please refer following articles

Post a Comment

www.CodeNirvana.in

Protected by Copyscape Online Copyright Protection
Copyright © Compile Mode