Compare commits

...

18 Commits

Author SHA1 Message Date
e6bcdbe2b4 15.6.3 Defining Variable-Length Routes; UNIT TEST: TESTING CATCHALL SEGMENT VARIABLES 2021-11-24 19:12:29 +11:00
b9dc70e649 15.6.3 Defining Variable-Length Routes; Listing 15-23. Designating a Catchall Variable in the RouteConfig.cs File 2021-11-24 19:11:59 +11:00
488ab5bfac 15.6.2.1 Using Optional URL Segments to Enforce Separation of Concerns; UNIT TESTING: OPTIONAL URL SEGMENTS 2021-11-24 19:08:15 +11:00
e738287bc2 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 2021-11-24 19:06:29 +11:00
ed932d419f 15.6.2 Defining Optional URL Segments; Listinig 15-20. Checking for an Optional Segment Variable in the HomeController.cs File 2021-11-24 18:47:39 +11:00
e43c56e68a 15.6.2 Defining Optional URL Segments; Listinig 15-19. Specifying an Optional URL Segment in the RouteConfig.cs File 2021-11-24 18:37:05 +11:00
b1390aba96 15.6.1 Using Custom Variables as Action Method Parameters; Listing 15-18. Adding an Action Method Parameter in the HomeController.cs File 2021-11-23 22:56:17 +11:00
0f14a97ae2 15.6 Defining Custom Segment Variables; UNIT TEST: TESTING CUSTOM SEGMENT VARIABLES 2021-11-23 22:51:24 +11:00
e7f13be7d8 15.6 Defining Custom Segment Variables; Listing 15-17. The Contents of CustomVariable.cshtml File 2021-11-23 21:16:29 +11:00
98748c4b3d 15.6 Defining Custom Segment Variables; Listing 15-16. Accessing a Custom Segment Varaible in an Action Method in the HomeController.cs File 2021-11-23 21:09:53 +11:00
fc704d2a68 15.6 Defining Custom Segment Variables; Listing 15-15. Defining Additional Variables in a URL Pattern in the RouteConfig.cs File 2021-11-23 21:01:56 +11:00
c4f05470ab 15.5 Using Static URL Segments; Listing 15-14. Aliasing a Controller and an Action in the RouteConfig.cs File 2021-11-23 20:42:13 +11:00
7e57cd2d16 15.5 Using Static URL Segments; Listing 15-13. Mixing Static URL Segments and Default Values in the RouteConfig.cs File 2021-11-23 20:34:18 +11:00
2ea5c23a4d 15.5 Using Static URL Segments; Listing 15-12. A URL Pattern with a Mixed Segment in the RouteConfig.cs File 2021-11-23 11:59:50 +11:00
981ebcaf47 15.5 Using Static URL Segments; Listing 15-11. A URL Pattern with Static Segments in the RouteConfig.cs File 2021-11-23 11:52:55 +11:00
6112f51510 15.4 Defining Default Values; Unit Testing: Default Values 2021-11-23 00:15:22 +11:00
ff4638e027 15.4 Defining Default Values; Listing 15-10 Providing Action and Controller Default Values in RouteConfig.cs File 2021-11-23 00:07:16 +11:00
cf7a377fe0 15.4 Defining Default Values; Listing 15-9 Providing a Default Value in RouteConfig.cs File 2021-11-23 00:06:28 +11:00
5 changed files with 37 additions and 11 deletions

View File

@ -99,15 +99,14 @@ namespace UrlsAndRoutes.Tests
[TestMethod]
public void TestIncomingRoutes()
{
// check for URL that is hoped for
TestRouteMatch("~/Admin/Index", "Admin", "Index");
// check that values are being obtained from segments
TestRouteMatch("~/One/Two", "One", "Two");
// ensure that too many or too few segments fails to match
TestRouteFail("~/Admin/Index/Segment");
TestRouteFail("~/Admin");
TestRouteMatch("~/", "Home", "Index");
TestRouteMatch("~/Customer", "Customer", "index");
TestRouteMatch("~/Customer/List", "Customer", "List");
TestRouteMatch("~/Customer/List/All", "Customer", "List", new { id = "All" });
TestRouteMatch("~/Customer/List/All/Delete", "Customer", "List",
new { id = "All", catchall = "Delete" });
TestRouteMatch("~/Customer/List/All/Delete/Perm", "Customer", "List",
new { id = "All", catchall = "Delete/Param" });
}
}
}

View File

@ -11,7 +11,8 @@ namespace UrlsAndRoutes
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("MyRoute", "{controller}/{action}");
routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional});
}
}
}

View File

@ -15,5 +15,13 @@ namespace UrlsAndRoutes.Controllers
ViewBag.Action = "Index";
return View("ActionName");
}
public ActionResult CustomVariable(string id = "DefaultId")
{
ViewBag.Controller = "Home";
ViewBag.Action = "CustomVariable";
ViewBag.CustomVariable = id;
return View();
}
}
}

View File

@ -104,6 +104,7 @@
<Content Include="Views\web.config" />
<None Include="packages.config" />
<Content Include="Views\Shared\ActionName.cshtml" />
<Content Include="Views\Home\CustomVariable.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
@ -115,7 +116,6 @@
<Folder Include="App_Data\" />
<Folder Include="Models\" />
<Folder Include="Views\Admin\" />
<Folder Include="Views\Home\" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

View File

@ -0,0 +1,18 @@

@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Custom Variable</title>
</head>
<body>
<div>The controller is: @ViewBag.Controller</div>
<div>The action is: @ViewBag.Action</div>
<div>The custom variable is: @ViewBag.CustomVariable</div>
</body>
</html>