In previous blog post I had discussed about how to post form data to back end, to controller and then to database, and here in this tutorial session I will show you how to get data asynchronously to server ie controller and from there to database. So how to do this? Honestly speaking its very simple, a few steps and its done.
So lets start by creating a new application, name it as you want. Create a new controller and a view against that controller.
We are going to implement a Login form, it may be any others also. Whatever the form is functionality is same. I choose a login form to show you choose according to your requirement.
For login form we need two text boxes and one button. So design it quickly.
Now add the jquery method.Before do any type of jquery operation add the jquery api. Here I am using Google api. You can also use it from different other sites(like jquery.com) or you can use it as your own.
Now we can do coding of jquery.
On the btnLogin click we will call the get method and pass the variable to controller. Before we proceed we have to create a new controller where we can catch the data we are sending via jquery.
So create a new controller named Login.
Now write down these jquery code into your view page.
After this add a onclick properties to btnLogin.
Now its turn for the Login controller.
Here I have created a method CheckLogin under clsUser. In that method I am actually checking whether the user is valid or not. So lets take a look on that method.
Here I am using a simple ADO.NET code. Its not the right process to so. I have just used just because to make this short. I highly recommend to use parametrize query to do such thing.
Add a new connection string in web.config to configure your server with this. And what else? your application is done. You have created it. Now test it and enjoy.
Download the full source code here.