How to Pass Object, Objects List and Data from Controller to View Using ASP.Net Core MVC

Project Download

Introduction
In this article we will see how to pass object, objects list and data from controller to view using asp.net core.

Create ASP.NET Core MVC Project
On the visual studio, create new ASP.NET Core Web Application

Shamim Academy

Select Empty Template

Shamim

Click ok button

Add Configurations
Open Startup.cs file and add some configurations as below:

Entity Class

Create a folder named Models. In Models folder, create an entity class named Student as below:

For passing Object
Create Controller
Now we will create a folder named Controllers. In Controllers Folder, create a controller class named PassingObject as below:

Create View
Create a new folder named Views. In this folder, create a new folder named PassingObject. In Passing Object folder, Create a new razor view named Index.cshtml as below:

Application Structure

Run Application 

For Passing Objects List
Create Controller
In Controllers folder, create a controller class named ObjectsList as below:

View

Create a folder named ObjectsList in Views Folder, In ObjectsList folder, create a view named Index.cshtml as below:

Application Structure

Run Application

For Passing Data
Create Controller
In Controllers folder, create a controller class named PassingData as below:

View
Create a folder named PassingData in Views Folder, In PassingData folder, create a view named Index.cshtml as below:

Application Structure

Run Application

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *