• How to post data from view to controller using Ajax in ASP.NET MVC?

    by  • October 7, 2015 • jQuery and Microsoft .NET, Microsoft .NET AJAX, Microsoft ASP.NET MVC • 0 Comments


    There are multiple ways to pass data from view to controller in ASP.NET MVC. One way to pass data from view to controller through Ajax. This article will show you how to pass data from view to controller using Ajax.

    1) Model.cs:

    Add a model class and named it ModelClass.cs in Model folder. In the ModelClass.cs paste the following code.

    2) View.cshtml:

    Add a view and named it Index.cshtml. In the view.cshtml paste the following code.  When user click on button it will call GetCustomerData action in Home Controller and pass CustomerName, CustomerAge and MobilePass to this action and at the end GetCustomerData action return JSon data that is showing in alert of success function.


    Add a controller and named it HomeController.cs in Controller folder. In the HomeController.cs paste the following code. GetCustomerData() method will receive parameter from AJax function and it return model class data in JSon  format.

    Best WordPress Themes and Plugins with Great Team and Support!

    Avatar of Abdul Rehman


    Abdul Rehman writes on .NET technologies at GetCodeSnippet.com. GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.


    Leave a Reply