Call Web API Using jQuery AJAX in ASP.NET Core Web Applications
1. Create Project:
2. Add WebAPI folder and add web api controller and rename to MyAPIController:
3. Write Methods in MyAPIController to be called from Jquery: Add model class ‘APIModel’ to declare variables with correct data type to store value. The methods should be given method type (HttpPost, HttpGet etc.) and route path in order to hit the method.
4. Create View page in Home View: Add view elements. Let’s just create a textbox to input the value and a button ‘Submit Value’.
5. Add jquery.js, javascript file APIView.js and write jquery and ajax functions in javascript file ‘APIView.js’ to call the web api. Add json2.js file to pass json formatted values
6. Link jquery.js at the top view page. Link the javascript file,json.js file to view page below the jquery link.
7. Run the project and see if web api is called and the value is passed: