From the course: Learning ASP.NET Core MVC

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Render data with strongly typed views

Render data with strongly typed views

From the course: Learning ASP.NET Core MVC

Render data with strongly typed views

- [Instructor] While the ViewBag property is a convenient way to pass data around, its dynamic nature often leaves a lot to be desired. So, in this video I'm going to show you an alternative to the dynamic ViewBag approach for passing data from a controller to a view, which is to pass a strongly typed model into your view instead. In order to create a strongly typed view, we first need to create a type that we can use as our model. Before we do that, let's create a model's folder in the root of the application to hold all of our model classes in. It's important to note that like the controller classes, it really doesn't matter to MVC where you model classes live. You'll often see this models folder as a practical convention. But these models can live anywhere, even in another project. In fact, that's usually a pretty good idea. Anyway, regardless of where it lives, let's create a brand new class. Just a simple type named post, with a couple of properties in it. Title, posted, author…

Contents