In order to improve UI interactivity in web development, it is often
recommended to utilize Ajax to load/process small web parts/components
independently on the same page.
Today, I shall be demonstrating the integration of Ajax call without passing any parameters with the ASP.NET MVC5 platform.

Prerequisites
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 "MVCAjaxNoParam".
Step 2
Create a "Controllerss\HomeController.cs" file with default Index method and GetData(...) method for ajax call with the following lines of code:
- ...
- public ActionResult GetData()
- {
- // Initialization.
- JsonResult result = new JsonResult();
- ...
- // Initialization.
- DataTable data = DataTable();
- // Loading Data.
- ...
- // Prepare Json response.
- 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 and simply loaded a sample data in DataTable structure and then 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:


Join the conversation! Your thoughts help the community grow.