From 5945309b128dc485a31c0b401fa9885c1f331a27 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Tue, 13 Jul 2021 23:51:02 +1000 Subject: [PATCH] e.g. 3.5 Retrieving a ViewBag Data Value e.g. 3.6 Displaying Details of the Party --- .../PartyInvites/Controllers/HomeController.cs | 2 ++ chap3_your_first_mvc_app/PartyInvites/Views/Home/Index.cshtml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs b/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs index 2165da2..106c868 100644 --- a/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs +++ b/chap3_your_first_mvc_app/PartyInvites/Controllers/HomeController.cs @@ -10,6 +10,8 @@ namespace PartyInvites.Controllers { public ActionResult Index() { + int hour = DateTime.Now.Hour; + ViewBag.Greeting = hour < 12 ? "Good morning" : "Good afternoon"; return View(); } diff --git a/chap3_your_first_mvc_app/PartyInvites/Views/Home/Index.cshtml b/chap3_your_first_mvc_app/PartyInvites/Views/Home/Index.cshtml index 09121c7..6104f79 100644 --- a/chap3_your_first_mvc_app/PartyInvites/Views/Home/Index.cshtml +++ b/chap3_your_first_mvc_app/PartyInvites/Views/Home/Index.cshtml @@ -10,7 +10,7 @@
- Hello, world (from the view) + @ViewBag.Greeting, world (from the view)
\ No newline at end of file