Strongly Typed View in ASP.NET Core MVC

In the previous tutorial, we saw how to build a simple HTML form. We made use of the ViewModel, but did not pass the instance of it to the view. The ViewModel can be passed from the controller to the view either using  Viewbag or Viewdata. The ASP.NET Core provides the ability to pass strongly typed models or objects to a view. This approach helps us with the intellisense and better compile-time checking of our code. The scaffolding mechanism in Visual Studio can be used to create the View. Let us learn all these in the article.

Passing data from Controller to View in ASP.NET Core MVC

In this tutorial, we are going to learn how to pass data from Controller to View. We should create View Models with all of the needed data and pass it from the controller to the View. The View Models can be passed to the View by creating a dynamic property in ViewBag. It can be passed using the Model Property of the ViewData. The Model property allows us to create the strongly typed Views using the @model directive. We will look at all these in this tutorial.

ViewBag and ViewData in ASP.NET Core

The Views needs to get the data from the controller. One of the ways in which to pass the data to the view is using the ViewData or ViewBag object. In this tutorial, we look at how to use ViewBag and ViewData to pass the data to the View.

Scroll to Top