Web
Analytics
Read Controller action using Jquery in ASP.NET MVC and LINQ - Tutorial

For Consultation : +91 9887575540

Stay Connected :

Read Controller action using Jquery in ASP.NET MVC and LINQ

In this example I am going to demonstrate that how we can read controller action using jquery and json. Action will return output in json format.here I am using $.getJSON method of jquery.

Step1. Create new Empty MVC Project

Open Visual Studio->New Project->Visual C#->Web->ASP.NET Web application->Give Project Name->Select Empty Template->Check MVC Checkbox->Click OK

Step 2. Now to we will add LINQ to sql classes(dbml) in Models folder .

Right click on Model folder =>select new Item->Select Data tab at left side in opened window->Select LINQ to sql classes in middle.->Give the name of your dbml file(here DataClasses1.dbml)

Step 3. Connect with sql database .We have to create sql database in sql server management studio.I supposed you  already created it so I am not telling way to create it.

Open server explorer(Ctrl+alt+s)->Right click on data connection and select add connection->Enter your sql server name->Select Database(my Database name is Ganesha).

(In this process DataClasses1DataContext will be created in models folder)

LINQ_database_Table

Create table sql query

 

I want to perform CRUD on this table.

Step 4. In server explorer window expand newly added(ganesha) database->Drag and drop Employee Table on design serface.+Ctrl S

(It will add employee model in DataClasses1DataContext)

Step 5. Create controller in controller folder-> Select Create Empty controller ->Controller Name(Here ReadJSON)=>OK(This Controller Index action will read JSON controller action of Employee Controller)

Step 6. Create controller in controller folder-> Select Create Empty controller ->Controller Name(Here Employee)=>OK(In this Controller we will write JSON action which will be read by ReadJSON’s Index Action (and Index View)

Step 7: Create Images folder and add ajax_linq_MVC.png.(Download (Search ajaxloader.gif image)it from internet)

 

Pass namespace using LINQCRUD.Models

Write following code in Employee Controller

 

In ReadJSONController.cs

 

 

Step 7: Add Empty Index View in above action.

Step8 : Install Jquery.3.0.0.js from NuGet Package Manager.

 

Output_LINQ_MVC_Jquery_JSON

 

Download Source Code

Select your currency