Premium Only Content

Part 5 Views in an mvc application
In this video we will discuss views. Please watch Part 4 of MVC tutorial before proceeding. Let's change the Index() method in HomeController to return a list of country names. Since country names are strings, return List of strings. Get rid of id and name parameters.
Run the application and notice that the output is not as expected.
System.Collections.Generic.List`1[System.String]
To correct this problem, let's add a view to our project.
1. Right click on the Index() function
2. Click on "Add View"
3. Notice that, the view name in "Add View" dialog box matches the name of the controller action method
4. Select "Razor" as the view engine
5. Leave the rest of the defaults as is, and click "Add" button
We will discuss ViewBag & ViewData, and the differences between them in our next video session. For now, understand that, ViewBag & ViewData is a mechanism to pass data from the controller to the view.
Please Note: To pass data from controller to a view, It's always a good practice to use strongly typed view models instead of using ViewBag & ViewData. We will discuss view models in a later video session.
Please Note: We use "@" symbol to switch between html and c# code. We will discuss razor views and their syntax in a later video session.
-
LIVE
Russell Brand
2 hours agoEstablishment ATTACK RFK Jr As China Unveils Weapons AIMED at America’s Bases! - SF629
3,548 watching -
LIVE
Dr Disrespect
3 hours agoLIVE - DR DISRESPECT - MARVEL RIVALS, PUBG, OFF THE GRID - TRIPLE THREAT GAME CHALLENGE
1,723 watching -
LIVE
Tucker Carlson
1 hour agoBill Gates, Truth About Vaccines, & Big Pharma’s Plot to Destroy Doctors Who Question ”The Science”
5,205 watching -
20:08
Professor Nez
24 minutes ago🚨🔥BRUTAL! Trump ROASTS Newsom SO BAD it BREAKS Gavin for Good
1 -
2:04:38
Side Scrollers Podcast
3 hours agoEveryone HATES Baseball Karen + Gaming’s Newest Virtue Signal + MORE | Side Scrollers Live
9701 -
LIVE
StoneMountain64
1 hour agoDelta Force Budget vs JUICER Loadouts
106 watching -
LIVE
Sean Unpaved
2 hours agoYardline Yarns: Giants Need Juice, Bills-Ravens Classic, Dolphins' Soft Spot & Packers Prove It
145 watching -
1:05:03
Timcast
2 hours agoDemocrat media COVERS UP Irina Zarutska Murder, Second White Woman Killed, Trump Says WAR
79.3K77 -
2:07:35
Steven Crowder
5 hours agoThe Murder of A Ukrainian Refugee is A Tipping Point in American History
277K291 -
1:03:37
The Rubin Report
3 hours agoMedia Caught Trying to Ignore Ugly New Details of Charlotte Train Stabbing Caught on Tape
36K72