Join Jess Chadwick for an in-depth discussion in this video Pass data from the controller to the view, part of Learning ASP.NET Core MVC.
- [Voiceover] Now that I've shown you the basics…of working with Razor Views,…let's see how controllers can pass data…to the view so that the view…can display that data to the user.…For example, let's say we want to be able…to set the title, author, date of the post,…and the body of the post as variables…in the post action of the blog controller,…and pass that info to be rendered in the view.…The easiest way to do this is with the ViewBag property.…This property is a dynamic object…that is accessible both on the controller and the view.…
So, whenever we set a value…on this object in the controller,…it will also be available in the view.…And since it's dynamic,…we can just access it as though…the property already exists, like this.…Then, we can create the view for this action,…and just read those properties from the ViewBag…to render them right in the page in the appropriate places.…Now, when we run the site and access the blog post,…we can see the data we've set in the controller…getting passed to the view, and rendered in the browser.…
- Building blocks of ASP.NET Core applications
- Creating a new project
- Responding to HTTP requests
- Serving static files
- Understanding the MVC pattern
- Handling requests with controllers
- Rendering HTML with Razor
- Rendering data, view markup, and view logic
- Creating HTML forms
- Validating form data
- Reading and writing from a database with Entity Framework
- Improving the user experience
- Exposing data with a web API
- Securing your ASP.NET application
Skill Level Intermediate
1. The Basics
2. The Model-View-Controller (MVC) Pattern
Understand routing4m 24s
3. Render HTML with Views
4. Work with Data
5. Improve User Experience with Ajax and Web APIs
6. Secure Your Application
Next steps1m 42s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.