From e738287bc29c7e2961533600f8ada0d90145de91 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 24 Nov 2021 19:06:29 +1100 Subject: [PATCH] 15.6.2.1 Using Optional URL Segments to Enforce Separation of Concerns; Listing 15-21. Defining a Default Value for an Action Method Parameter in the HomeController.cs File --- UrlsAndRoutes/UrlsAndRoutes/Controllers/HomeController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UrlsAndRoutes/UrlsAndRoutes/Controllers/HomeController.cs b/UrlsAndRoutes/UrlsAndRoutes/Controllers/HomeController.cs index 2df8f1a..d70f5bb 100644 --- a/UrlsAndRoutes/UrlsAndRoutes/Controllers/HomeController.cs +++ b/UrlsAndRoutes/UrlsAndRoutes/Controllers/HomeController.cs @@ -16,11 +16,11 @@ namespace UrlsAndRoutes.Controllers return View("ActionName"); } - public ActionResult CustomVariable(string id) + public ActionResult CustomVariable(string id = "DefaultId") { ViewBag.Controller = "Home"; ViewBag.Action = "CustomVariable"; - ViewBag.CustomVariable = id ?? ""; + ViewBag.CustomVariable = id; return View(); } }