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
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Render HTML with Razor3m 51s
-
(Locked)
Render dynamic content with Razor5m 1s
-
(Locked)
Reuse shared HTML markup with layouts3m 7s
-
(Locked)
Rendering reusable sections of content in a layout2m 34s
-
(Locked)
Pass data from the controller to the view1m 56s
-
(Locked)
Render data with strongly typed views2m 16s
-
-
-
-
-