Compare commits
18 Commits
3ddca950e3
...
e6bcdbe2b4
Author | SHA1 | Date | |
---|---|---|---|
e6bcdbe2b4 | |||
b9dc70e649 | |||
488ab5bfac | |||
e738287bc2 | |||
ed932d419f | |||
e43c56e68a | |||
b1390aba96 | |||
0f14a97ae2 | |||
e7f13be7d8 | |||
98748c4b3d | |||
fc704d2a68 | |||
c4f05470ab | |||
7e57cd2d16 | |||
2ea5c23a4d | |||
981ebcaf47 | |||
6112f51510 | |||
ff4638e027 | |||
cf7a377fe0 |
@ -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" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
18
UrlsAndRoutes/UrlsAndRoutes/Views/Home/CustomVariable.cshtml
Normal file
18
UrlsAndRoutes/UrlsAndRoutes/Views/Home/CustomVariable.cshtml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user