Grouping Gridview in MVC 4

Introduction

In this post, I explain how to Group data in Gridview using MVC. Sometimes we need to show group data in our MVC Application like show List of State group by Country. Here I have done this using MVC 4. Steps are given below:-

Step-2: Add a Database.

Step-3: Create two tables and insert data for show grouped data in Gridview

Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name > Ok.
In this example, I have created two table 1. CountryMaster 2. StateMaster.
Create the table and insert data for Show in grouped gridview.

Step-5: Creare a ModelView

Here in this example, I need a ViewModel for getting data as a single entity.
Add a Folder(ViewModel) into your project root directory. > Right Click on the folder > Add > Class > Enter Class name > Add.
Write the following code to your class.