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

chap15
Jason Zhu 2021-11-24 19:06:29 +11:00
parent ed932d419f
commit e738287bc2
1 changed files with 2 additions and 2 deletions

View File

@ -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 ?? "<no value>";
ViewBag.CustomVariable = id;
return View();
}
}