Ajax methodology in web development can or cannot have input query parameters for processing/loading web parts on the web page. However, complex logic and improved performance measures demand Ajax call to pass multiple input query parameters whether in a typical multiple parameter format or JSON input format.
Today, I shall be demonstrating the integration of Ajax calls by passing multiple input query parameters with the ASP.NET MVC5 platform.

Prerequisites
The following are some prerequisites before you proceed any further in this tutorial,
- Knowledge of Jquery.
- Knowledge of HTML.
- Knowledge of JavaScript.
- Knowledge of Bootstrap.
- Knowledge of ASP.NET MVC5.
- Knowledge of C# Programming.
The example code is being developed in Microsoft Visual Studio 2019 Professional.
Let's begin now.
Step 1
Create a new MVC web project and name it "MVCAjaxWithParam".
Step 2
Create a "Controllerss\HomeController.cs" file with default Index method and GetData(...) method with two input query parameters for Ajax call with following lines of code i.e.
- ...
- public ActionResult GetData(int customerID, string fname = "")
- {
- // Initialization.
- JsonResult result = new JsonResult();
- DataTable data = DataTable();
- ...
- // Load Data.
- ...
- // Filter data with input query parameters.
- ...
- // Prepare Ajax JSON Data Result.
- result = this.Json(JsonConvert.SerializeObject(data), JsonRequestBehavior.AllowGet);
- ...
- // Return info.
- return result;
- }
- ...
In the above code, I have created a simple “GetData(…)” method with ActionResult returning type for client-side ajax calling to return result data in JSON format. I have first loaded my data in DataTable structure, then I have applied the input query filter with OR condition and finally, I have prepared my JSON response.
Step 3
Now, create the subsequent view "Views\Home\Index.cshtml"of "Controllerss\HomeController.cs" index method and add table HTML tag as shown below i.e.



Joe PoolPosted Feb 5, 2021, 6:44 PM
I am getting "500 (Internal Server Error) using jquery-2.2.0.js, line 9172: `xhr.send( options.hasContent && options.data || null );`. It says, "Failed to load resource." What am I doing wrong here?
Shubham TrivediPosted Nov 27, 2020, 7:35 AM
Brother, Now I wanna Pass DataSet instead of C# DataTable, How to, Please help, If you can...
Dipa MehtaPosted Mar 18, 2020, 10:49 PM
Nice Article Asma on Ajax ..:)