Introduction
This article will explain to you how you can display multiple tables' record in a single view using ViewModel in ASP.Net MVC. For this article, you should have basic understanding of the following,
- Bootstrap 4
- MVC
- Entity Framework
- View Model
- SQL Server
Step 1
Open your favourite SQL server database any version. It doesn’t really matter. Create tables as shown below.
- CREATE TABLE [dbo].[Employee](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [Name] [nvarchar](50) NULL,
- [Gender] [char](10) NULL,
- [Age] [int] NULL,
- [Position] [nvarchar](50) NULL,
- [Office] [nvarchar](50) NULL,
- [Salary] [int] NULL,
- CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
- CREATE TABLE [dbo].[Department](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [DepartmentName] [nvarchar](50) NULL,
- CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
- CREATE TABLE [dbo].[Incentive](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [IncentiveAmount] [int] NULL,
- CONSTRAINT [PK_Incentive] PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO


















fatemeh qanbariPosted Sep 6, 2020, 3:01 AM
I want to post this parameters to my controller from my form How can I do?
Paul EvansPosted Aug 18, 2020, 5:06 AM
This is a great article Thanks very much. Simple to follow
ZIAD ABUQASEMPosted May 29, 2020, 10:05 AM
Assalam Alykum brother Farhan , I have a question , i need to add department name to the employee list , i tried but i cannot select <td>@employee.DepartmentName</td> in first employee list , how can you add it , thank you for your effort .
Sourav Kumar DasPosted Oct 14, 2019, 2:17 AM
Awesome Article.