Monday, June 16, 2014

Call Controller Action Method From JQuery Using Ajax

Call Controller Action Method From JQuery Using Ajax




Today I just came across an issue and implemented code that I thought to share with my techie friends who may also face such an issue, which is to call a Controller's action method from jQuery using Ajax.
Calling from the Client Side.


The following is a sample of calling an Ajax method from the client side:

Down here I've demonstrated the code implementation and some builtin functions to prevent its natural behavior using preventDefault.
After clicking on the selected class element it first calls the ev.preventDefault(); that prevents the stopping of its natural event functionality. The URL accepts the ControllerName/Action name. The data : takes a parameter that is passed to a specified action method that executes and later returns the Model to the View. The type "post" means it's a POST method that takes some input.
If everything goes ok than it redirects to the desired page with the prevention of the natural behavior.
Cheers .Net

Thanks & Regards,


Post a Comment